futures_util/sink/
close.rs

1use core::marker::PhantomData;
2use core::pin::Pin;
3use futures_core::future::Future;
4use futures_core::task::{Context, Poll};
5use 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"]
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 { sink, _phantom: PhantomData }
23    }
24}
25
26impl<Si: Sink<Item> + Unpin + ?Sized, Item> Future for Close<'_, Si, Item> {
27    type Output = Result<(), Si::Error>;
28
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}