Coroutine

Struct Coroutine 

Source
pub struct Coroutine<Y, T, R> { /* private fields */ }
Expand description

A coroutine that can yield values of type Y, can be resumed with a value of type R and completes with a value of type T.

Implementations§

Source§

impl<Y, T, R> Coroutine<Y, T, R>
where T: 'static,

Source

pub fn new<F>(f: impl FnOnce(YieldHandle<Y, R>, R) -> F + 'static) -> Self
where F: Future<Output = T> + 'static,

Creates a new coroutine from a function that takes the YieldHandle and the initial value. The function must return a future that resolves to the final value of type T.

Source

pub fn resume_with(&mut self, resume: R) -> State<Y, T>

Resumes the coroutine with a value of type R.

Source§

impl<Y, T> Coroutine<Y, T, ()>
where T: 'static,

Source

pub fn resume(&mut self) -> State<Y, T>

Resumes the generator.

Auto Trait Implementations§

§

impl<Y, T, R> Freeze for Coroutine<Y, T, R>

§

impl<Y, T, R> !RefUnwindSafe for Coroutine<Y, T, R>

§

impl<Y, T, R> !Send for Coroutine<Y, T, R>

§

impl<Y, T, R> !Sync for Coroutine<Y, T, R>

§

impl<Y, T, R> Unpin for Coroutine<Y, T, R>

§

impl<Y, T, R> !UnwindSafe for Coroutine<Y, T, R>

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.