1use crate::Stream;
2
3use core::marker::PhantomData;
4use core::pin::Pin;
5use core::task::{Context, Poll};
6
7/// Stream for the [`pending`](fn@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> {}
13unsafe impl<T> Send for Pending<T> {}
14unsafe 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/// ```
40pub const fn pending<T>() -> Pending<T> {
41 Pending(PhantomData)
42}
43
44impl<T> Stream for Pending<T> {
45 type Item = T;
46
47 fn poll_next(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Option<T>> {
48 Poll::Pending
49 }
50
51 fn size_hint(&self) -> (usize, Option<usize>) {
52 (0, None)
53 }
54}
55