Struct tvix_eval::generators::Gen
source · pub struct Gen<Y, R, F>where
F: Future,{
airlock: Airlock<Y, R>,
future: Pin<Box<F>>,
}
Expand description
This is a generator which stores its state on the heap.
Fields§
§airlock: Airlock<Y, R>
§future: Pin<Box<F>>
Implementations§
source§impl<Y, R, F> Gen<Y, R, F>where
F: Future,
impl<Y, R, F> Gen<Y, R, F>where
F: Future,
sourcepub fn new(producer: impl FnOnce(Co<Airlock<Y, R>>) -> F) -> Gen<Y, R, F>
pub fn new(producer: impl FnOnce(Co<Airlock<Y, R>>) -> F) -> Gen<Y, R, F>
Creates a new generator from a function.
The function accepts a Co
object, and returns a future. Every time
the generator is resumed, the future is polled. Each time the future is
polled, it should do one of two things:
- Call
co.yield_()
, and then returnPoll::Pending
. - Drop the
Co
, and then returnPoll::Ready
.
Typically this exchange will happen in the context of an async fn
.
sourcepub fn resume_with(
&mut self,
arg: R,
) -> GeneratorState<Y, <F as Future>::Output>
pub fn resume_with( &mut self, arg: R, ) -> GeneratorState<Y, <F as Future>::Output>
Resumes execution of the generator.
arg
is the resume argument. If the generator was previously paused by
awaiting a future returned from co.yield()
, that future will complete,
and return arg
.
If the generator yields a value, Yielded
is returned. Otherwise,
Completed
is returned.
source§impl<Y, F> Gen<Y, (), F>where
F: Future,
impl<Y, F> Gen<Y, (), F>where
F: Future,
sourcepub fn resume(&mut self) -> GeneratorState<Y, <F as Future>::Output>
pub fn resume(&mut self) -> GeneratorState<Y, <F as Future>::Output>
Resumes execution of the generator.
If the generator yields a value, Yielded
is returned. Otherwise,
Completed
is returned.
sourcepub fn async_resume(
&mut self,
) -> impl Future<Output = GeneratorState<Y, <F as Future>::Output>>
pub fn async_resume( &mut self, ) -> impl Future<Output = GeneratorState<Y, <F as Future>::Output>>
Resumes execution of the generator.
If the generator pauses without yielding, Poll::Pending
is returned.
If the generator yields a value, Poll::Ready(Yielded)
is returned.
Otherwise, Poll::Ready(Completed)
is returned.
Trait Implementations§
source§impl<Y, F> IntoIterator for Gen<Y, (), F>
impl<Y, F> IntoIterator for Gen<Y, (), F>
Auto Trait Implementations§
impl<Y, R, F> Freeze for Gen<Y, R, F>
impl<Y, R, F> !RefUnwindSafe for Gen<Y, R, F>
impl<Y, R, F> !Send for Gen<Y, R, F>
impl<Y, R, F> !Sync for Gen<Y, R, F>
impl<Y, R, F> Unpin for Gen<Y, R, F>
impl<Y, R, F> !UnwindSafe for Gen<Y, R, F>
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<C> Generator for C
impl<C> Generator for C
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more