Coverage Report

Created: 2025-11-16 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/futures-util-0.3.21/src/sink/drain.rs
Line
Count
Source
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> Sink<T> for Drain<T> {
36
    type Error = Never;
37
38
0
    fn poll_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
39
0
        Poll::Ready(Ok(()))
40
0
    }
41
42
0
    fn start_send(self: Pin<&mut Self>, _item: T) -> Result<(), Self::Error> {
43
0
        Ok(())
44
0
    }
45
46
0
    fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
47
0
        Poll::Ready(Ok(()))
48
0
    }
49
50
0
    fn poll_close(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
51
0
        Poll::Ready(Ok(()))
52
0
    }
53
}