diff options
Diffstat (limited to 'src/io/util/shutdown.rs')
-rw-r--r-- | src/io/util/shutdown.rs | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/src/io/util/shutdown.rs b/src/io/util/shutdown.rs index 33ac0ac..6d30b00 100644 --- a/src/io/util/shutdown.rs +++ b/src/io/util/shutdown.rs @@ -1,18 +1,24 @@ use crate::io::AsyncWrite; +use pin_project_lite::pin_project; use std::future::Future; use std::io; +use std::marker::PhantomPinned; use std::pin::Pin; use std::task::{Context, Poll}; -cfg_io_util! { +pin_project! { /// A future used to shutdown an I/O object. /// /// Created by the [`AsyncWriteExt::shutdown`][shutdown] function. /// [shutdown]: crate::io::AsyncWriteExt::shutdown + #[must_use = "futures do nothing unless you `.await` or poll them"] #[derive(Debug)] pub struct Shutdown<'a, A: ?Sized> { a: &'a mut A, + // Make this future `!Unpin` for compatibility with async trait methods. + #[pin] + _pin: PhantomPinned, } } @@ -21,7 +27,10 @@ pub(super) fn shutdown<A>(a: &mut A) -> Shutdown<'_, A> where A: AsyncWrite + Unpin + ?Sized, { - Shutdown { a } + Shutdown { + a, + _pin: PhantomPinned, + } } impl<A> Future for Shutdown<'_, A> @@ -30,19 +39,8 @@ where { type Output = io::Result<()>; - fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { - let me = &mut *self; - Pin::new(&mut *me.a).poll_shutdown(cx) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn assert_unpin() { - use std::marker::PhantomPinned; - crate::is_unpin::<Shutdown<'_, PhantomPinned>>(); + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { + let me = self.project(); + Pin::new(me.a).poll_shutdown(cx) } } |