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