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