diff --git a/src/tools/async_io.rs b/src/tools/async_io.rs index c3b9d935..4e4107c0 100644 --- a/src/tools/async_io.rs +++ b/src/tools/async_io.rs @@ -16,18 +16,18 @@ pub enum EitherStream { Right(R), } -impl AsyncRead for EitherStream { +impl AsyncRead for EitherStream { fn poll_read( self: Pin<&mut Self>, cx: &mut Context, buf: &mut [u8], ) -> Poll> { - match unsafe { self.get_unchecked_mut() } { + match self.get_mut() { EitherStream::Left(ref mut s) => { - unsafe { Pin::new_unchecked(s) }.poll_read(cx, buf) + Pin::new(s).poll_read(cx, buf) } EitherStream::Right(ref mut s) => { - unsafe { Pin::new_unchecked(s) }.poll_read(cx, buf) + Pin::new(s).poll_read(cx, buf) } } } @@ -47,51 +47,51 @@ impl AsyncRead for EitherStream { where B: bytes::BufMut, { - match unsafe { self.get_unchecked_mut() } { + match self.get_mut() { EitherStream::Left(ref mut s) => { - unsafe { Pin::new_unchecked(s) }.poll_read_buf(cx, buf) + Pin::new(s).poll_read_buf(cx, buf) } EitherStream::Right(ref mut s) => { - unsafe { Pin::new_unchecked(s) }.poll_read_buf(cx, buf) + Pin::new(s).poll_read_buf(cx, buf) } } } } -impl AsyncWrite for EitherStream { +impl AsyncWrite for EitherStream { fn poll_write( self: Pin<&mut Self>, cx: &mut Context, buf: &[u8], ) -> Poll> { - match unsafe { self.get_unchecked_mut() } { + match self.get_mut() { EitherStream::Left(ref mut s) => { - unsafe { Pin::new_unchecked(s) }.poll_write(cx, buf) + Pin::new(s).poll_write(cx, buf) } EitherStream::Right(ref mut s) => { - unsafe { Pin::new_unchecked(s) }.poll_write(cx, buf) + Pin::new(s).poll_write(cx, buf) } } } fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { - match unsafe { self.get_unchecked_mut() } { + match self.get_mut() { EitherStream::Left(ref mut s) => { - unsafe { Pin::new_unchecked(s) }.poll_flush(cx) + Pin::new(s).poll_flush(cx) } EitherStream::Right(ref mut s) => { - unsafe { Pin::new_unchecked(s) }.poll_flush(cx) + Pin::new(s).poll_flush(cx) } } } fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { - match unsafe { self.get_unchecked_mut() } { + match self.get_mut() { EitherStream::Left(ref mut s) => { - unsafe { Pin::new_unchecked(s) }.poll_shutdown(cx) + Pin::new(s).poll_shutdown(cx) } EitherStream::Right(ref mut s) => { - unsafe { Pin::new_unchecked(s) }.poll_shutdown(cx) + Pin::new(s).poll_shutdown(cx) } } } @@ -104,12 +104,12 @@ impl AsyncWrite for EitherStream { where B: bytes::Buf, { - match unsafe { self.get_unchecked_mut() } { + match self.get_mut() { EitherStream::Left(ref mut s) => { - unsafe { Pin::new_unchecked(s) }.poll_write_buf(cx, buf) + Pin::new(s).poll_write_buf(cx, buf) } EitherStream::Right(ref mut s) => { - unsafe { Pin::new_unchecked(s) }.poll_write_buf(cx, buf) + Pin::new(s).poll_write_buf(cx, buf) } } } @@ -180,7 +180,7 @@ pub struct HyperAccept(pub T); impl hyper::server::accept::Accept for HyperAccept where - T: TryStream, + T: TryStream + Unpin, I: AsyncRead + AsyncWrite, { type Conn = I; @@ -190,7 +190,7 @@ where self: Pin<&mut Self>, cx: &mut Context, ) -> Poll>> { - let this = unsafe { self.map_unchecked_mut(|this| &mut this.0) }; + let this = Pin::new(&mut self.get_mut().0); this.try_poll_next(cx) } }