Skip to main content

NeverDone

Struct NeverDone 

Source
pub struct NeverDone<Iter> { /* private fields */ }
Expand description

An AsyncIterator wrapper that never returns Done

An AsyncIterator caller is generally supposed to drop the iterator promptly after poll_next returns Done. for await loops do this, and drive_next also does this, without waiting for its body to finish. But some async iterators, for example FuturesUnordered and StreamMap, work differently. These allow their caller to add work to them at any time. If they run out of work, their poll_next methods return Done, but they can return Some again later if more work is added again. This doesn’t play well with for await or drive_next, because they’ll drop the iterator the first time they see Done. (for await also makes it hard to add work during the loop, because it has no equivalent of with_pin_mut or with_mut).

NeverDone is a workaround for this problem. It’s a thin AsyncIterator wrapper that never returns Done. When the inner iterator would return Done, NeverDone returns Pending instead. This means that the inner iterator’s poll_next method might get called again after returning Done, which isn’t generally allowed, and which will cause some iterators to panic. It’s the caller’s responsibility to only use NeverDone with async iterators that allow this.

See the example in the module level docs.

Implementations§

Source§

impl<Iter> NeverDone<Iter>

Source

pub fn new(iter: Iter) -> Self

Wrap an AsyncIterator with NeverDone.

Source

pub fn into_inner(self) -> Iter

Consume the NeverDone and return the inner AsyncIterator.

Source

pub fn as_pin_mut(self: Pin<&mut Self>) -> Pin<&mut Iter>

Return a pinned reference to the inner AsyncIterator.

Trait Implementations§

Source§

impl<Iter: AsyncIterator> AsyncIterator for NeverDone<Iter>

Source§

type Item = <Iter as AsyncIterator>::Item

🔬This is a nightly-only experimental API. (async_iterator)
The type of items yielded by the async iterator.
Source§

fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> PollNext<Self::Item>

🔬This is a nightly-only experimental API. (async_iterator)
Attempts to pull out the next item of this async iterator, registering the current task for wakeup if an item is not yet available, and returning Done if the async iterator is exhausted. Read more
Source§

fn poll_progress(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()>

🔬This is a nightly-only experimental API. (async_iterator)
Allows this async iterator to make progress internally, even though the next item is not yet needed. Read more
Source§

fn size_hint(&self) -> (usize, Option<usize>)

🔬This is a nightly-only experimental API. (async_iterator)
Returns the bounds on the remaining length of the async iterator. Read more
Source§

impl<Iter: Debug> Debug for NeverDone<Iter>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Iter> Deref for NeverDone<Iter>

Source§

type Target = Iter

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Iter

Dereferences the value.
Source§

impl<Iter> DerefMut for NeverDone<Iter>

Source§

fn deref_mut(&mut self) -> &mut Iter

Mutably dereferences the value.
Source§

impl<'__pin, Iter> Unpin for NeverDone<Iter>
where PinnedFieldsOf<__Origin<'__pin, Iter>>: Unpin,

Auto Trait Implementations§

§

impl<Iter> Freeze for NeverDone<Iter>
where Iter: Freeze,

§

impl<Iter> RefUnwindSafe for NeverDone<Iter>
where Iter: RefUnwindSafe,

§

impl<Iter> Send for NeverDone<Iter>
where Iter: Send,

§

impl<Iter> Sync for NeverDone<Iter>
where Iter: Sync,

§

impl<Iter> UnsafeUnpin for NeverDone<Iter>
where Iter: UnsafeUnpin,

§

impl<Iter> UnwindSafe for NeverDone<Iter>
where Iter: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<I> IntoAsyncIterator for I
where I: AsyncIterator,

Source§

type Item = <I as AsyncIterator>::Item

🔬This is a nightly-only experimental API. (async_iterator)
The type of the item yielded by the iterator
Source§

type IntoAsyncIter = I

🔬This is a nightly-only experimental API. (async_iterator)
The type of the resulting iterator
Source§

fn into_async_iter(self) -> <I as IntoAsyncIterator>::IntoAsyncIter

🔬This is a nightly-only experimental API. (async_iterator)
Converts self into an async iterator
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.