/rust/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.28/src/sink/close.rs
Line | Count | Source (jump to first uncovered line) |
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 | 0 | #[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> { |
21 | 0 | pub(super) fn new(sink: &'a mut Si) -> Self { |
22 | 0 | Self { sink, _phantom: PhantomData } |
23 | 0 | } |
24 | | } |
25 | | |
26 | | impl<Si: Sink<Item> + Unpin + ?Sized, Item> Future for Close<'_, Si, Item> { |
27 | | type Output = Result<(), Si::Error>; |
28 | | |
29 | 0 | fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { |
30 | 0 | Pin::new(&mut self.sink).poll_close(cx) |
31 | 0 | } |
32 | | } |