Coverage Report

Created: 2025-10-13 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-stream-0.1.17/src/empty.rs
Line
Count
Source
1
use crate::Stream;
2
3
use core::marker::PhantomData;
4
use core::pin::Pin;
5
use core::task::{Context, Poll};
6
7
/// Stream for the [`empty`](fn@empty) function.
8
#[derive(Debug)]
9
#[must_use = "streams do nothing unless polled"]
10
pub struct Empty<T>(PhantomData<T>);
11
12
impl<T> Unpin for Empty<T> {}
13
unsafe impl<T> Send for Empty<T> {}
14
unsafe impl<T> Sync for Empty<T> {}
15
16
/// Creates a stream that yields nothing.
17
///
18
/// The returned stream is immediately ready and returns `None`. Use
19
/// [`stream::pending()`](super::pending()) to obtain a stream that is never
20
/// ready.
21
///
22
/// # Examples
23
///
24
/// Basic usage:
25
///
26
/// ```
27
/// use tokio_stream::{self as stream, StreamExt};
28
///
29
/// #[tokio::main]
30
/// async fn main() {
31
///     let mut none = stream::empty::<i32>();
32
///
33
///     assert_eq!(None, none.next().await);
34
/// }
35
/// ```
36
0
pub const fn empty<T>() -> Empty<T> {
37
0
    Empty(PhantomData)
38
0
}
39
40
impl<T> Stream for Empty<T> {
41
    type Item = T;
42
43
0
    fn poll_next(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Option<T>> {
44
0
        Poll::Ready(None)
45
0
    }
46
47
0
    fn size_hint(&self) -> (usize, Option<usize>) {
48
0
        (0, Some(0))
49
0
    }
50
}