| 1 | use core::marker::PhantomData; |
| 2 | use core::pin::Pin; |
| 3 | |
| 4 | use crate::stream::Stream; |
| 5 | use crate::task::{Context, Poll}; |
| 6 | |
| 7 | /// Creates a stream that doesn't yield any items. |
| 8 | /// |
| 9 | /// This `struct` is created by the [`empty`] function. See its |
| 10 | /// documentation for more. |
| 11 | /// |
| 12 | /// [`empty`]: fn.empty.html |
| 13 | /// |
| 14 | /// # Examples |
| 15 | /// |
| 16 | /// ``` |
| 17 | /// # async_std::task::block_on(async { |
| 18 | /// # |
| 19 | /// use async_std::prelude::*; |
| 20 | /// use async_std::stream; |
| 21 | /// |
| 22 | /// let mut s = stream::empty::<i32>(); |
| 23 | /// |
| 24 | /// assert_eq!(s.next().await, None); |
| 25 | /// # |
| 26 | /// # }) |
| 27 | /// ``` |
| 28 | pub fn empty<T>() -> Empty<T> { |
| 29 | Empty { |
| 30 | _marker: PhantomData, |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | /// A stream that doesn't yield any items. |
| 35 | /// |
| 36 | /// This stream is constructed by the [`empty`] function. |
| 37 | /// |
| 38 | /// [`empty`]: fn.empty.html |
| 39 | #[derive (Debug)] |
| 40 | pub struct Empty<T> { |
| 41 | _marker: PhantomData<T>, |
| 42 | } |
| 43 | |
| 44 | impl<T> Stream for Empty<T> { |
| 45 | type Item = T; |
| 46 | |
| 47 | fn poll_next(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Option<Self::Item>> { |
| 48 | Poll::Ready(None) |
| 49 | } |
| 50 | } |
| 51 | |