futures_util/stream/
empty.rs

1use core::marker;
2
3use futures_core::{Stream, Poll, Async};
4use futures_core::task;
5
6/// A stream which contains no elements.
7///
8/// This stream can be created with the `stream::empty` function.
9#[derive(Debug)]
10#[must_use = "streams do nothing unless polled"]
11pub struct Empty<T, E> {
12    _data: marker::PhantomData<(T, E)>,
13}
14
15/// Creates a stream which contains no elements.
16///
17/// The returned stream will always return `Ready(None)` when polled.
18pub fn empty<T, E>() -> Empty<T, E> {
19    Empty { _data: marker::PhantomData }
20}
21
22impl<T, E> Stream for Empty<T, E> {
23    type Item = T;
24    type Error = E;
25
26    fn poll_next(&mut self, _: &mut task::Context) -> Poll<Option<Self::Item>, Self::Error> {
27        Ok(Async::Ready(None))
28    }
29}