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>
impl<T, P> Generator<T, P>
sourcepub 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,
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.
sourcepub 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,
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.
sourcepub fn boxed(
gen: impl FnOnce(Remit<'static, T>) -> P
) -> GeneratorIterator<'static, T, P> ⓘ
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.