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