async_std/stream/empty.rs
1use core::marker::PhantomData;
2use core::pin::Pin;
3
4use crate::stream::Stream;
5use 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/// ```
28pub 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)]
40pub struct Empty<T> {
41 _marker: PhantomData<T>,
42}
43
44impl<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}