diff --git a/library/core/src/async_iter/mod.rs b/library/core/src/async_iter/mod.rs index a5b03b7dd4f14..b97c54ad9846a 100644 --- a/library/core/src/async_iter/mod.rs +++ b/library/core/src/async_iter/mod.rs @@ -123,6 +123,9 @@ mod async_iter; mod from_iter; +mod pending; pub use async_iter::{AsyncIterator, IntoAsyncIterator}; pub use from_iter::{FromIter, from_iter}; +#[unstable(feature = "stream_pending", issue = "91683")] +pub use pending::{Pending, pending}; diff --git a/library/core/src/async_iter/pending.rs b/library/core/src/async_iter/pending.rs new file mode 100644 index 0000000000000..74611595e9117 --- /dev/null +++ b/library/core/src/async_iter/pending.rs @@ -0,0 +1,52 @@ +use crate::async_iter::AsyncIterator; +use crate::fmt; +use crate::marker::PhantomData; +use crate::pin::Pin; +use crate::task::{Context, Poll}; + +/// Creates a stream that never returns any elements. +/// +/// The returned stream will always return `Pending` when polled. +#[unstable(feature = "stream_pending", issue = "91683")] +pub fn pending() -> Pending { + Pending { _t: PhantomData } +} + +/// A stream that never returns any elements. +/// +/// This stream is created by the [`pending`] function. See its +/// documentation for more. +#[unstable(feature = "stream_pending", issue = "91683")] +pub struct Pending { + _t: PhantomData, +} + +#[unstable(feature = "stream_pending", issue = "91683")] +impl AsyncIterator for Pending { + type Item = T; + + fn poll_next(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { + Poll::Pending + } + + fn size_hint(&self) -> (usize, Option) { + (0, Some(0)) + } +} + +#[unstable(feature = "stream_pending", issue = "91683")] +impl Unpin for Pending {} + +#[unstable(feature = "stream_pending", issue = "91683")] +impl fmt::Debug for Pending { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_tuple("Pending").finish() + } +} + +#[unstable(feature = "stream_pending", issue = "91683")] +impl Clone for Pending { + fn clone(&self) -> Self { + pending() + } +}