1use super::assert_stream;
2use core::marker::PhantomData;
3use core::pin::Pin;
4use futures_core::stream::{FusedStream, Stream};
5use futures_core::task::{Context, Poll};
6
7/// Stream for the [`empty`] function.
8#[derive(Debug)]
9#[must_use = "streams do nothing unless polled"]
10pub struct Empty<T> {
11 _phantom: PhantomData<T>,
12}
13
14/// Creates a stream which contains no elements.
15///
16/// The returned stream will always return `Ready(None)` when polled.
17pub fn empty<T>() -> Empty<T> {
18 assert_stream::<T, _>(Empty { _phantom: PhantomData })
19}
20
21impl<T> Unpin for Empty<T> {}
22
23impl<T> FusedStream for Empty<T> {
24 fn is_terminated(&self) -> bool {
25 true
26 }
27}
28
29impl<T> Stream for Empty<T> {
30 type Item = T;
31
32 fn poll_next(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Option<Self::Item>> {
33 Poll::Ready(None)
34 }
35
36 fn size_hint(&self) -> (usize, Option<usize>) {
37 (0, Some(0))
38 }
39}
40
41impl<T> Clone for Empty<T> {
42 fn clone(&self) -> Self {
43 empty()
44 }
45}
46