async_sink/ext/
flush.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 [`flush`](super::SinkExt::flush) method.
8#[derive(Debug)]
9#[must_use = "futures do nothing unless you `.await` or poll them"]
10pub struct Flush<'a, Si: ?Sized, Item> {
11    sink: &'a mut Si,
12    _phantom: PhantomData<fn(Item)>,
13}
14
15impl<Si: Unpin + ?Sized, Item> Unpin for Flush<'_, Si, Item> {}
16
17impl<'a, Si: Sink<Item> + Unpin + ?Sized, Item> Flush<'a, Si, Item> {
18    pub(super) fn new(sink: &'a mut Si) -> Self {
19        Self {
20            sink,
21            _phantom: PhantomData,
22        }
23    }
24}
25
26impl<Si: Sink<Item> + Unpin + ?Sized, Item> Future for Flush<'_, 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.as_mut().sink).poll_flush(cx)
31    }
32}