diff --git a/src/upgrade/connection.rs b/src/upgrade/connection.rs index d8331a57..abd47ec6 100644 --- a/src/upgrade/connection.rs +++ b/src/upgrade/connection.rs @@ -5,38 +5,41 @@ use std::task::{Context, Poll}; /// An upgraded HTTP connection. #[derive(Debug, Clone)] -pub struct Connection { - inner: Pin>, +pub struct RawConnection { + inner: Inner, } -impl Read for Connection { +/// A boxed upgraded HTTP connection. +pub type Connection = RawConnection>; + +/// Trait to signal the requirements for an underlying connection type. +pub trait InnerConnection: Read + Write + Send + Sync + Unpin {} +impl InnerConnection for T {} + +impl Read for RawConnection { fn poll_read( - self: Pin<&mut Self>, + mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll> { - let this = self.project(); - Pin::new(this.inner).poll_read(cx, buf) + Pin::new(&mut self.inner).poll_read(cx, buf) } } -impl Write for Connection { +impl Write for RawConnection { fn poll_write( - self: Pin<&mut Self>, + mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll> { - let this = self.project(); - Pin::new(this.inner).poll_write(cx, buf) + Pin::new(&mut self.inner).poll_write(cx, buf) } - fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - let this = self.project(); - Pin::new(this.inner).poll_flush(cx) + fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + Pin::new(&mut self.inner).poll_flush(cx) } - fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - let this = self.project(); - Pin::new(this.inner).poll_close(cx) + fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + Pin::new(&mut self.inner).poll_close(cx) } }