1 use crate::io::AsyncWrite;
2 
3 use pin_project_lite::pin_project;
4 use std::future::Future;
5 use std::io;
6 use std::marker::PhantomPinned;
7 use std::pin::Pin;
8 use std::task::{Context, Poll};
9 
10 pin_project! {
11     /// A future used to shutdown an I/O object.
12     ///
13     /// Created by the [`AsyncWriteExt::shutdown`][shutdown] function.
14     /// [shutdown]: [`crate::io::AsyncWriteExt::shutdown`]
15     #[must_use = "futures do nothing unless you `.await` or poll them"]
16     #[derive(Debug)]
17     pub struct Shutdown<'a, A: ?Sized> {
18         a: &'a mut A,
19         // Make this future `!Unpin` for compatibility with async trait methods.
20         #[pin]
21         _pin: PhantomPinned,
22     }
23 }
24 
25 /// Creates a future which will shutdown an I/O object.
shutdown<A>(a: &mut A) -> Shutdown<'_, A> where A: AsyncWrite + Unpin + ?Sized,26 pub(super) fn shutdown<A>(a: &mut A) -> Shutdown<'_, A>
27 where
28     A: AsyncWrite + Unpin + ?Sized,
29 {
30     Shutdown {
31         a,
32         _pin: PhantomPinned,
33     }
34 }
35 
36 impl<A> Future for Shutdown<'_, A>
37 where
38     A: AsyncWrite + Unpin + ?Sized,
39 {
40     type Output = io::Result<()>;
41 
poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>42     fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
43         let me = self.project();
44         Pin::new(me.a).poll_shutdown(cx)
45     }
46 }
47