• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 [`flush`](super::SinkExt::flush) method.
8 #[derive(Debug)]
9 #[must_use = "futures do nothing unless you `.await` or poll them"]
10 pub struct Flush<'a, Si: ?Sized, Item> {
11     sink: &'a mut Si,
12     _phantom: PhantomData<fn(Item)>,
13 }
14 
15 // Pin is never projected to a field.
16 impl<Si: Unpin + ?Sized, Item> Unpin for Flush<'_, Si, Item> {}
17 
18 /// A future that completes when the sink has finished processing all
19 /// pending requests.
20 ///
21 /// The sink itself is returned after flushing is complete; this adapter is
22 /// intended to be used when you want to stop sending to the sink until
23 /// all current requests are processed.
24 impl<'a, Si: Sink<Item> + Unpin + ?Sized, Item> Flush<'a, Si, Item> {
new(sink: &'a mut Si) -> Self25     pub(super) fn new(sink: &'a mut Si) -> Self {
26         Self {
27             sink,
28             _phantom: PhantomData,
29         }
30     }
31 }
32 
33 impl<Si: Sink<Item> + Unpin + ?Sized, Item> Future for Flush<'_, Si, Item> {
34     type Output = Result<(), Si::Error>;
35 
poll( mut self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Self::Output>36     fn poll(
37         mut self: Pin<&mut Self>,
38         cx: &mut Context<'_>,
39     ) -> Poll<Self::Output> {
40         Pin::new(&mut self.sink).poll_flush(cx)
41     }
42 }
43