Skip to content

refactor(io,tls,ws)!: use pin-project-lite#720

Merged
Berrysoft merged 8 commits intocompio-rs:masterfrom
Berrysoft:dev/io-compat-pin
Mar 5, 2026
Merged

refactor(io,tls,ws)!: use pin-project-lite#720
Berrysoft merged 8 commits intocompio-rs:masterfrom
Berrysoft:dev/io-compat-pin

Conversation

@Berrysoft
Copy link
Member

I will try TAIT after this PR.

@Berrysoft Berrysoft added package: io Related to compio-io package: tls Related to compio-tls package: ws Related to compio-ws labels Mar 1, 2026
@Berrysoft Berrysoft requested review from George-Miao and Copilot March 1, 2026 17:29
@Berrysoft Berrysoft self-assigned this Mar 1, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the compio-io compat adapter and downstream TLS/WebSocket integration to use pin-project-lite-based pinning, adjusting rustls stream types to be pinned and tightening various generic bounds accordingly.

Changes:

  • Refactor compio_io::compat::AsyncStream to use pin_project_lite + PhantomPinned and update call sites to pin the stream before using futures_util extension traits.
  • Update rustls integration to wrap compat streams as Pin<Box<AsyncStream<_>>> (and adjust related From impls / acceptor types).
  • Add Unpin bounds to several public APIs (TlsConnector, TlsAcceptor, websocket TLS helpers) to satisfy the new compat adapter constraints.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
compio-ws/src/tls.rs Tightens stream bounds to Unpin for TLS/plain wrapping to match updated TLS connector constraints.
compio-tls/src/stream.rs Changes rustls inner stream type to Pin<Box<AsyncStream<_>>> and tightens TlsStream trait impl bounds.
compio-tls/src/rtls.rs Updates rustls lazy acceptor/handshake wrapper types to use pinned compat streams and adds Unpin bounds.
compio-tls/src/adapter.rs Pins compat streams for rustls connect/accept and adds Unpin to public generic bounds.
compio-io/src/compat/async_stream.rs Switches to pin-project-lite, makes AsyncStream !Unpin, and reworks internal pin/borrow handling.
compio-io/tests/compat.rs Updates tests to pin AsyncStream before using futures_util extension traits.
compio-io/Cargo.toml Adds optional pin-project-lite dependency and wires it into the compat feature.
Comments suppressed due to low confidence (2)

compio-tls/src/adapter.rs:89

  • TlsConnector::connect now requires S: Unpin even though only the rustls branch needs pinning (native-tls / py-dynamic-openssl paths don’t inherently require Unpin). This is a public API tightening that can break downstream users with !Unpin streams.

If possible, keep the original bound and add Unpin only when the rustls feature is enabled/used (e.g., via a rustls-specific helper method, a cfg-gated impl, or by adjusting compat::AsyncStream so it doesn’t require S: Unpin).

    pub async fn connect<S: AsyncRead + AsyncWrite + Unpin + 'static>(
        &self,
        domain: &str,
        stream: S,
    ) -> io::Result<TlsStream<S>> {

compio-tls/src/stream.rs:133

  • TlsStream<S>’s AsyncRead/AsyncWrite impls now require S: Unpin, which is a public behavior change (some downstream S types that were previously supported may no longer compile). If this is only needed for the rustls backend, consider constraining Unpin to the rustls-specific path/types rather than the blanket impl bounds, or document this as a breaking change.
impl<S: AsyncRead + AsyncWrite + Unpin + 'static> AsyncRead for TlsStream<S> {
    async fn read<B: IoBufMut>(&mut self, mut buf: B) -> BufResult<usize, B> {
        let slice = buf.as_uninit();
        slice.fill(MaybeUninit::new(0));
        // SAFETY: The memory has been initialized

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Berrysoft Berrysoft changed the title feat(io): use pin-project-lite refactor(io): use pin-project-lite Mar 1, 2026
@Berrysoft Berrysoft added the refactor Refactoring existing code label Mar 1, 2026
@Berrysoft Berrysoft changed the title refactor(io): use pin-project-lite refactor!(io,tls,ws): use pin-project-lite Mar 2, 2026
@Berrysoft Berrysoft changed the title refactor!(io,tls,ws): use pin-project-lite refactor(io,tls,ws)!: use pin-project-lite Mar 2, 2026
Copy link
Member

@George-Miao George-Miao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Berrysoft Berrysoft merged commit 27aa339 into compio-rs:master Mar 5, 2026
63 checks passed
@Berrysoft Berrysoft deleted the dev/io-compat-pin branch March 5, 2026 18:57
@github-actions github-actions bot mentioned this pull request Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: io Related to compio-io package: tls Related to compio-tls package: ws Related to compio-ws refactor Refactoring existing code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants