1 use core::marker::PhantomData;
2 use core::pin::Pin;
3 use futures_core::future::Future;
4 use futures_core::task::{Context, Poll};
5 use futures_sink::Sink;
6 
7 /// Future for the [`close`](super::SinkExt::close) method.
8 #[derive(Debug)]
9 #[must_use = "futures do nothing unless you `.await` or poll them"]
10 pub struct Close<'a, Si: ?Sized, Item> {
11     sink: &'a mut Si,
12     _phantom: PhantomData<fn(Item)>,
13 }
14 
15 impl<Si: Unpin + ?Sized, Item> Unpin for Close<'_, Si, Item> {}
16 
17 /// A future that completes when the sink has finished closing.
18 ///
19 /// The sink itself is returned after closing is complete.
20 impl<'a, Si: Sink<Item> + Unpin + ?Sized, Item> Close<'a, Si, Item> {
new(sink: &'a mut Si) -> Self21     pub(super) fn new(sink: &'a mut Si) -> Self {
22         Self { sink, _phantom: PhantomData }
23     }
24 }
25 
26 impl<Si: Sink<Item> + Unpin + ?Sized, Item> Future for Close<'_, Si, Item> {
27     type Output = Result<(), Si::Error>;
28 
poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>29     fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
30         Pin::new(&mut self.sink).poll_close(cx)
31     }
32 }
33