/rust/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.21/src/stream/empty.rs
Line | Count | Source (jump to first uncovered line) |
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. |
17 | 0 | pub fn empty<T>() -> Empty<T> { |
18 | 0 | assert_stream::<T, _>(Empty { _phantom: PhantomData }) |
19 | 0 | } |
20 | | |
21 | | impl<T> Unpin for Empty<T> {} |
22 | | |
23 | | impl<T> FusedStream for Empty<T> { |
24 | 0 | fn is_terminated(&self) -> bool { |
25 | 0 | true |
26 | 0 | } |
27 | | } |
28 | | |
29 | | impl<T> Stream for Empty<T> { |
30 | | type Item = T; |
31 | | |
32 | 0 | fn poll_next(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Option<Self::Item>> { |
33 | 0 | Poll::Ready(None) |
34 | 0 | } |
35 | | |
36 | 0 | fn size_hint(&self) -> (usize, Option<usize>) { |
37 | 0 | (0, Some(0)) |
38 | 0 | } |
39 | | } |
40 | | |
41 | | impl<T> Clone for Empty<T> { |
42 | 0 | fn clone(&self) -> Self { |
43 | 0 | empty() |
44 | 0 | } |
45 | | } |