• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use super::assert_stream;
2 use core::marker::PhantomData;
3 use core::pin::Pin;
4 use futures_core::stream::{FusedStream, Stream};
5 use futures_core::task::{Context, Poll};
6 
7 /// Stream for the [`empty`] function.
8 #[derive(Debug)]
9 #[must_use = "streams do nothing unless polled"]
10 pub 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.
empty<T>() -> Empty<T>17 pub fn empty<T>() -> Empty<T> {
18     assert_stream::<T, _>(Empty {
19         _phantom: PhantomData
20     })
21 }
22 
23 impl<T> Unpin for Empty<T> {}
24 
25 impl<T> FusedStream for Empty<T> {
is_terminated(&self) -> bool26     fn is_terminated(&self) -> bool {
27         true
28     }
29 }
30 
31 impl<T> Stream for Empty<T> {
32     type Item = T;
33 
poll_next(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Option<Self::Item>>34     fn poll_next(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Option<Self::Item>> {
35         Poll::Ready(None)
36     }
37 
size_hint(&self) -> (usize, Option<usize>)38     fn size_hint(&self) -> (usize, Option<usize>) {
39         (0, Some(0))
40     }
41 }
42 
43 impl<T> Clone for Empty<T> {
clone(&self) -> Self44     fn clone(&self) -> Self {
45         empty()
46     }
47 }
48