Struct Generator

Source
pub struct Generator<'a, Input: 'a, Output: 'a, Stack: Stack> { /* private fields */ }
Expand description

Generator wraps a closure and allows suspending its execution more than once, returning a value each time.

If the closure finishes each other call to resume will yield None. If the closure panics the unwind will happen correctly across contexts.

Implementations§

Source§

impl<'a, Input, Output, Stack> Generator<'a, Input, Output, Stack>
where Input: 'a, Output: 'a, Stack: Stack,

Source

pub fn new<F>(stack: Stack, f: F) -> Generator<'a, Input, Output, Stack>
where F: FnOnce(&Yielder<Input, Output>, Input) + 'a,

Create a new generator from a stack and closure.

Source

pub fn resume(&mut self, input: Input) -> Option<Output>

Resume the generator yielding the next value.

Source

pub fn started(&self) -> bool

Returns true if the execution of the passed in closure started

Source

pub fn finished(&self) -> bool

Returns true if the generator finished running.

Source

pub fn stack(self) -> Stack

Consume the generator and extract the stack.

Trait Implementations§

Source§

impl<'a, Input, Output, Stack> Drop for Generator<'a, Input, Output, Stack>
where Input: 'a, Output: 'a, Stack: Stack,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a, Input, Output, Stack> Send for Generator<'a, Input, Output, Stack>
where Input: 'a, Output: 'a, Stack: Stack,

Auto Trait Implementations§

§

impl<'a, Input, Output, Stack> Freeze for Generator<'a, Input, Output, Stack>
where Stack: Freeze,

§

impl<'a, Input, Output, Stack> RefUnwindSafe for Generator<'a, Input, Output, Stack>
where Stack: RefUnwindSafe, Input: RefUnwindSafe, Output: RefUnwindSafe,

§

impl<'a, Input, Output, Stack> !Sync for Generator<'a, Input, Output, Stack>

§

impl<'a, Input, Output, Stack> Unpin for Generator<'a, Input, Output, Stack>
where Stack: Unpin,

§

impl<'a, Input, Output, Stack> UnwindSafe for Generator<'a, Input, Output, Stack>
where Stack: UnwindSafe, Input: RefUnwindSafe, Output: RefUnwindSafe,

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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.