Struct remit::Generator

source ·
pub struct Generator<T, P> { /* private fields */ }
Expand description

The storage used for iterators that poll a generator.

Implementations§

source§

impl<T, P> Generator<T, P>

source

pub fn new() -> Self

Provides the storage to be pinned when not using an allocation.

source

pub fn of<'s, G>(self: Pin<&'s mut Self>, gen: G) -> GeneratorIterator<'s, T, P> where G: for<'a> RemitWithLifetime<'a, T, ()> + FnOnce(Remit<'static, T>) -> P,

Takes the pinned storage and the generator and provides an iterator. Stack based (does not use an allocation).

The internal storage assumes the generator was valid for a provided 'static, but requires the generator to be valid for all provided lifetimes. That is, the Remit provided to the generator cannot be moved out, even if at first glance it appears the storage does not have that restriction. In effect, this relaxes the lifetime requirements of the storage, but not the provided generator.

source

pub fn parameterized<'s, G, X>( self: Pin<&'s mut Self>, gen: G, parameter: X ) -> GeneratorIterator<'s, T, P> where G: for<'a> RemitWithLifetime<'a, T, (X,)> + FnOnce(X, Remit<'static, T>) -> P,

The same as Generator::of() but allows passing a parameter in.

source

pub fn boxed( gen: impl FnOnce(Remit<'static, T>) -> P ) -> GeneratorIterator<'static, T, P>

Uses an allocation so that the iterator does not need to be borrowed. Useful for returning an iterator from a function, where it can’t be pinned to the stack.

The generator only needs to be valid for 'static; it does not need to be valid for all lifetimes.

To pass in parameters, use a capturing closure.

Auto Trait Implementations§

§

impl<T, P> !RefUnwindSafe for Generator<T, P>

§

impl<T, P> Send for Generator<T, P>where P: Send, T: Send,

§

impl<T, P> !Sync for Generator<T, P>

§

impl<T, P> !Unpin for Generator<T, P>

§

impl<T, P> UnwindSafe for Generator<T, P>where P: UnwindSafe, T: 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<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, 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.