Skip to content

add core::async_iter::pending #142177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions library/core/src/async_iter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
52 changes: 52 additions & 0 deletions library/core/src/async_iter/pending.rs
Original file line number Diff line number Diff line change
@@ -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<T>() -> Pending<T> {
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> {
_t: PhantomData<T>,
}

#[unstable(feature = "stream_pending", issue = "91683")]
impl<T> AsyncIterator for Pending<T> {
type Item = T;

fn poll_next(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Option<Self::Item>> {
Poll::Pending
}

fn size_hint(&self) -> (usize, Option<usize>) {
(0, Some(0))
}
}

#[unstable(feature = "stream_pending", issue = "91683")]
impl<T> Unpin for Pending<T> {}

#[unstable(feature = "stream_pending", issue = "91683")]
impl<T> fmt::Debug for Pending<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("Pending").finish()
}
}

#[unstable(feature = "stream_pending", issue = "91683")]
impl<T> Clone for Pending<T> {
fn clone(&self) -> Self {
pending()
}
}
Loading