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/pending.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 [`pending`](fn@pending) function.
8
#[derive(Debug)]
9
#[must_use = "streams do nothing unless polled"]
10
pub struct Pending<T>(PhantomData<T>);
11
12
impl<T> Unpin for Pending<T> {}
13
unsafe impl<T> Send for Pending<T> {}
14
unsafe impl<T> Sync for Pending<T> {}
15
16
/// Creates a stream that is never ready
17
///
18
/// The returned stream is never ready. Attempting to call
19
/// [`next()`](crate::StreamExt::next) will never complete. Use
20
/// [`stream::empty()`](super::empty()) to obtain a stream that is is
21
/// immediately empty but returns no values.
22
///
23
/// # Examples
24
///
25
/// Basic usage:
26
///
27
/// ```no_run
28
/// use tokio_stream::{self as stream, StreamExt};
29
///
30
/// #[tokio::main]
31
/// async fn main() {
32
///     let mut never = stream::pending::<i32>();
33
///
34
///     // This will never complete
35
///     never.next().await;
36
///
37
///     unreachable!();
38
/// }
39
/// ```
40
0
pub const fn pending<T>() -> Pending<T> {
41
0
    Pending(PhantomData)
42
0
}
43
44
impl<T> Stream for Pending<T> {
45
    type Item = T;
46
47
0
    fn poll_next(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Option<T>> {
48
0
        Poll::Pending
49
0
    }
50
51
0
    fn size_hint(&self) -> (usize, Option<usize>) {
52
0
        (0, None)
53
0
    }
54
}