1use crate::io::AsyncWrite;
2
3use pin_project_lite::pin_project;
4use std::future::Future;
5use std::io;
6use std::marker::PhantomPinned;
7use std::pin::Pin;
8use std::task::{Context, Poll};
9
10pin_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.
26pub(super) fn shutdown<A>(a: &mut A) -> Shutdown<'_, A>
27where
28 A: AsyncWrite + Unpin + ?Sized,
29{
30 Shutdown {
31 a,
32 _pin: PhantomPinned,
33 }
34}
35
36impl<A> Future for Shutdown<'_, A>
37where
38 A: AsyncWrite + Unpin + ?Sized,
39{
40 type Output = io::Result<()>;
41
42 fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
43 let me: Projection<'_, '_, A> = self.project();
44 Pin::new(pointer:me.a).poll_shutdown(cx)
45 }
46}
47