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.

See the module-level docs for examples.

Fields§

§airlock: Airlock<Y, R>§future: Pin<Box<F>>

Implementations§

source§

impl<Y, R, F> Gen<Y, R, F>
where F: Future,

source

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 return Poll::Pending.
  • Drop the Co, and then return Poll::Ready.

Typically this exchange will happen in the context of an async fn.

See the module-level docs for examples.

source

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.

See the module-level docs for examples.

source§

impl<Y, F> Gen<Y, (), F>
where F: Future,

source

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.

See the module-level docs for examples.

source

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.

See the module-level docs for examples.

Trait Implementations§

source§

impl<Y, R, F> Coroutine for Gen<Y, R, F>
where F: Future,

§

type Yield = Y

The type of value this generator yields.
§

type Resume = R

The type of value this generator accepts as a resume argument.
§

type Return = <F as Future>::Output

The type of value this generator returns upon completion.
source§

fn resume_with( self: Pin<&mut Gen<Y, R, F>>, arg: R, ) -> GeneratorState<<Gen<Y, R, F> as Coroutine>::Yield, <Gen<Y, R, F> as Coroutine>::Return>

Resumes the execution of this generator. Read more
source§

impl<Y, F> IntoIterator for Gen<Y, (), F>
where F: Future<Output = ()>,

§

type Item = Y

The type of the elements being iterated over.
§

type IntoIter = IntoIter<Y, F>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> <Gen<Y, (), F> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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<C> Generator for C
where C: Coroutine<Resume = ()>,

§

type Yield = <C as Coroutine>::Yield

The type of value this generator yields.
§

type Return = <C as Coroutine>::Return

The type of value this generator returns upon completion.
source§

fn resume( self: Pin<&mut C>, ) -> GeneratorState<<C as Generator>::Yield, <C as Generator>::Return>

Resumes the execution of this generator.
source§

impl<T, U> Into<U> for T
where 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V