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>
impl<Iter> NeverDone<Iter>
Sourcepub fn into_inner(self) -> Iter
pub fn into_inner(self) -> Iter
Consume the NeverDone and return the inner AsyncIterator.
Sourcepub fn as_pin_mut(self: Pin<&mut Self>) -> Pin<&mut Iter>
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>
impl<Iter: AsyncIterator> AsyncIterator for NeverDone<Iter>
Source§type Item = <Iter as AsyncIterator>::Item
type Item = <Iter as AsyncIterator>::Item
async_iterator)Source§fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> PollNext<Self::Item>
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> PollNext<Self::Item>
async_iterator)Done if the async iterator is exhausted. Read moreimpl<'__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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<I> IntoAsyncIterator for Iwhere
I: AsyncIterator,
impl<I> IntoAsyncIterator for Iwhere
I: AsyncIterator,
Source§type Item = <I as AsyncIterator>::Item
type Item = <I as AsyncIterator>::Item
async_iterator)Source§type IntoAsyncIter = I
type IntoAsyncIter = I
async_iterator)Source§fn into_async_iter(self) -> <I as IntoAsyncIterator>::IntoAsyncIter
fn into_async_iter(self) -> <I as IntoAsyncIterator>::IntoAsyncIter
async_iterator)self into an async iterator