async_sink/ext/
close.rs

1use super::Sink;
2use core::future::Future;
3use core::marker::PhantomData;
4use core::pin::Pin;
5use core::task::{Context, Poll};
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"]
10pub struct Close<'a, Si: ?Sized, Item> {
11    sink: &'a mut Si,
12    _phantom: PhantomData<fn(Item)>,
13}
14
15impl<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.
20impl<'a, Si: Sink<Item> + Unpin + ?Sized, Item> Close<'a, Si, Item> {
21    pub(super) fn new(sink: &'a mut Si) -> Self {
22        Self {
23            sink,
24            _phantom: PhantomData,
25        }
26    }
27}
28
29impl<Si: Sink<Item> + Unpin + ?Sized, Item> Future for Close<'_, Si, Item> {
30    type Output = Result<(), Si::Error>;
31
32    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
33        Pin::new(&mut *self.sink).poll_close(cx)
34    }
35}