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