use crate::stream::Stream; use core::marker::PhantomData; use core::pin::Pin; use core::task::{Context, Poll}; /// Stream for the [`pending`](fn@pending) function. #[derive(Debug)] #[must_use = "streams do nothing unless polled"] pub struct Pending(PhantomData); impl Unpin for Pending {} unsafe impl Send for Pending {} unsafe impl Sync for Pending {} /// Creates a stream that is never ready /// /// The returned stream is never ready. Attempting to call /// [`next()`](crate::stream::StreamExt::next) will never complete. Use /// [`stream::empty()`](super::empty()) to obtain a stream that is is /// immediately empty but returns no values. /// /// # Examples /// /// Basic usage: /// /// ```no_run /// use tokio::stream::{self, StreamExt}; /// /// #[tokio::main] /// async fn main() { /// let mut never = stream::pending::(); /// /// // This will never complete /// never.next().await; /// /// unreachable!(); /// } /// ``` pub const fn pending() -> Pending { Pending(PhantomData) } impl Stream for Pending { type Item = T; fn poll_next(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { Poll::Pending } fn size_hint(&self) -> (usize, Option) { (0, None) } }