Struct async_gen::AsyncIter

source ·
pub struct AsyncIter<G> { /* private fields */ }
Expand description

An async iterator over the values yielded by an underlying generator.

Example

use async_gen::{gen, AsyncIter};
use futures_core::Stream;
use futures_util::StreamExt;

fn get_async_iter() -> impl Stream<Item = i32> {
    AsyncIter::from(gen! {
        yield 1;
        yield 2;
        yield 3;
    })
}

#[tokio::main]
async fn main() {
    let it = get_async_iter();
    let v: Vec<_> = it.collect().await;
    assert_eq!(v, [1, 2, 3]);
}

Implementations§

source§

impl<G: AsyncGenerator<Return = ()>> AsyncIter<G>

source

pub fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Option<G::Yield>>

Attempt to pull out the next value of this async iterator, registering the current task for wakeup if the value is not yet available, and returning None if the async iterator is exhausted.

Return value

There are several possible return values, each indicating a distinct async iterator state:

  • Poll::Pending means that this async iterator’s next value is not ready yet. Implementations will ensure that the current task will be notified when the next value may be ready.

  • Poll::Ready(Some(val)) means that the async iterator has successfully produced a value, val, and may produce further values on subsequent poll_next calls.

  • Poll::Ready(None) means that the async iterator has terminated, and poll_next should not be invoked again.

Panics

Once an async iterator has finished (returned Ready(None) from poll_next), calling its poll_next method again may panic, block forever, or cause other kinds of problems; the AsyncIterator trait places no requirements on the effects of such a call. However, as the poll_next method is not marked unsafe, Rust’s usual rules apply: calls must never cause undefined behavior (memory corruption, incorrect use of unsafe functions, or the like), regardless of the async iterator’s state.

Trait Implementations§

source§

impl<G: Clone> Clone for AsyncIter<G>

source§

fn clone(&self) -> AsyncIter<G>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<G> From<G> for AsyncIter<G>

source§

fn from(gen: G) -> Self

Converts to this type from the input type.
source§

impl<G: AsyncGenerator<Return = ()>> Stream for AsyncIter<G>

§

type Item = <G as AsyncGenerator>::Yield

Values yielded by the stream.
source§

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

Attempt to pull out the next value of this stream, registering the current task for wakeup if the value is not yet available, and returning None if the stream is exhausted. Read more
source§

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

Returns the bounds on the remaining length of the stream. Read more
source§

impl<'__pin, G> Unpin for AsyncIter<G>where __Origin<'__pin, G>: Unpin,

Auto Trait Implementations§

§

impl<G> RefUnwindSafe for AsyncIter<G>where G: RefUnwindSafe,

§

impl<G> Send for AsyncIter<G>where G: Send,

§

impl<G> Sync for AsyncIter<G>where G: Sync,

§

impl<G> UnwindSafe for AsyncIter<G>where G: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
source§

impl<S, T, E> TryStream for Swhere S: Stream<Item = Result<T, E>> + ?Sized,

§

type Ok = T

The type of successful values yielded by this future
§

type Error = E

The type of failures yielded by this future
source§

fn try_poll_next( self: Pin<&mut S>, cx: &mut Context<'_> ) -> Poll<Option<Result<<S as TryStream>::Ok, <S as TryStream>::Error>>>

Poll this TryStream as if it were a Stream. Read more