Coverage Report

Created: 2025-02-25 06:39

/rust/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/sink/drain.rs
Line
Count
Source (jump to first uncovered line)
1
use super::assert_sink;
2
use crate::never::Never;
3
use core::marker::PhantomData;
4
use core::pin::Pin;
5
use futures_core::task::{Context, Poll};
6
use futures_sink::Sink;
7
8
/// Sink for the [`drain`] function.
9
#[derive(Debug)]
10
#[must_use = "sinks do nothing unless polled"]
11
pub struct Drain<T> {
12
    marker: PhantomData<T>,
13
}
14
15
/// Create a sink that will just discard all items given to it.
16
///
17
/// Similar to [`io::Sink`](::std::io::Sink).
18
///
19
/// # Examples
20
///
21
/// ```
22
/// # futures::executor::block_on(async {
23
/// use futures::sink::{self, SinkExt};
24
///
25
/// let mut drain = sink::drain();
26
/// drain.send(5).await?;
27
/// # Ok::<(), futures::never::Never>(()) }).unwrap();
28
/// ```
29
0
pub fn drain<T>() -> Drain<T> {
30
0
    assert_sink::<T, Never, _>(Drain { marker: PhantomData })
31
0
}
32
33
impl<T> Unpin for Drain<T> {}
34
35
impl<T> Clone for Drain<T> {
36
0
    fn clone(&self) -> Self {
37
0
        drain()
38
0
    }
39
}
40
41
impl<T> Sink<T> for Drain<T> {
42
    type Error = Never;
43
44
0
    fn poll_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
45
0
        Poll::Ready(Ok(()))
46
0
    }
47
48
0
    fn start_send(self: Pin<&mut Self>, _item: T) -> Result<(), Self::Error> {
49
0
        Ok(())
50
0
    }
51
52
0
    fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
53
0
        Poll::Ready(Ok(()))
54
0
    }
55
56
0
    fn poll_close(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
57
0
        Poll::Ready(Ok(()))
58
0
    }
59
}