Skip to main content

GeneratorToken

Struct GeneratorToken 

Source
pub struct GeneratorToken<Y, A = ()>(/* private fields */);
Expand description

A generator token ties together the executor and the generator itself.

It is what allows us to yield values back out of the generator.

Implementations§

Source§

impl<Y, A> GeneratorToken<Y, A>

Source

pub async fn yield_(&self, value: Y) -> A

Yield a value from this generator, returning control back to the caller.

§Panics

Panics if evaluated in the context of a generator other than the one this token was created for.

Source

pub async fn argument(&self) -> A

Get the current argument without yielding.

Normally yield_ will yield a value and then read in the next argument. However, the very first argument passed in to the generator happens before the first call to yield_. This method is used to read that initial argument passed into the generator.

§Panics
  • Panics if evaluated in the context of a generator other than the one this token was created for.
  • Panics if there is no argument saved in the generator context. (e.g. yield has already been called or argument was called multiple times)

Auto Trait Implementations§

§

impl<Y, A> Freeze for GeneratorToken<Y, A>

§

impl<Y, A> RefUnwindSafe for GeneratorToken<Y, A>

§

impl<Y, A> Send for GeneratorToken<Y, A>
where Y: Send, A: Send,

§

impl<Y, A> Sync for GeneratorToken<Y, A>
where Y: Sync, A: Sync,

§

impl<Y, A> Unpin for GeneratorToken<Y, A>

§

impl<Y, A> UnsafeUnpin for GeneratorToken<Y, A>

§

impl<Y, A> UnwindSafe for GeneratorToken<Y, A>
where Y: UnwindSafe, A: UnwindSafe,

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.