1use crate::Stream;
2
3use core::marker::PhantomData;
4use core::pin::Pin;
5use core::task::{Context, Poll};
6
7#[derive(Debug)]
9#[must_use = "streams do nothing unless polled"]
10pub struct Empty<T>(PhantomData<T>);
11
12impl<T> Unpin for Empty<T> {}
13unsafe impl<T> Send for Empty<T> {}
14unsafe impl<T> Sync for Empty<T> {}
15
16pub const fn empty<T>() -> Empty<T> {
37 Empty(PhantomData)
38}
39
40impl<T> Stream for Empty<T> {
41 type Item = T;
42
43 fn poll_next(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<T>> {
44 #[cfg(feature = "rt")]
45 {
46 use tokio::task::coop;
47
48 let coop = std::task::ready!(coop::poll_proceed(_cx));
49 coop.made_progress();
50 }
51
52 Poll::Ready(None)
53 }
54
55 fn size_hint(&self) -> (usize, Option<usize>) {
56 (0, Some(0))
57 }
58}