CoroState

Enum CoroState 

Source
pub enum CoroState<S, R, T, F>
where S: Unpin, R: Unpin, F: Future<Output = T>,
{ Pending(PendingCoro<S, R, T, F>, S), Complete(T), }
Expand description

The intermediate state of a Coro while it is executing

Variants§

§

Pending(PendingCoro<S, R, T, F>, S)

The Coro yielded via yield_value. Call the send method on the inner PendingCoro to send a value back into the coroutine and convert it back to a ReadyCoro which can be resumed.

§

Complete(T)

The Coro is now complete and has returned a value.

Implementations§

Source§

impl<S, R, T, F> CoroState<S, R, T, F>
where S: Unpin, R: Unpin, F: Future<Output = T>,

Source

pub fn is_pending(&self) -> bool

Returns true if this is a Pending value.

§Example
let mut coro = Coro::from(async |handle: Handle<(), usize>| {
    let n = handle.yield_value(()).await;
    assert_eq!(n, 70);
});

let state = coro.resume();
assert_eq!(state.is_pending(), true);

coro = state.unwrap_pending(|_| 70);

let state = coro.resume();
assert_eq!(state.is_pending(), false);
Source

pub fn is_complete(&self) -> bool

Returns true if this is a Complete value.

§Example
let mut coro = Coro::from(async |handle: Handle<(), usize>| {
    let n = handle.yield_value(()).await;
    assert_eq!(n, 70);
});

let state = coro.resume();
assert_eq!(state.is_complete(), false);

coro = state.unwrap_pending(|_| 70);

let state = coro.resume();
assert_eq!(state.is_complete(), true);
Source

pub fn unwrap_pending(self, f: impl Fn(S) -> R) -> ReadyCoro<S, R, T, F>

Assume that this value is Pending and send a response to the underlying Coro using the provided mapping function to unwrap it into a ReadyCoro.

§Panics

This will panic if the value was Complete.

§Example
let mut coro = Coro::from(async |handle: Handle<(), usize>| {
    let n = handle.yield_value(()).await;
    assert_eq!(n, 70);
});

coro = coro.resume().unwrap_pending(|_| 70);
Source

pub fn unwrap(self) -> T

Assume that this value is Complete and unwrap it to return the inner value.

§Panics

This will panic if the value was Pending.

§Example
let mut coro = Coro::from(async |handle: Handle<(), ()>| {
    "done"
});

assert_eq!(coro.resume().unwrap(), "done");

Trait Implementations§

Source§

impl<S, R, T: Debug, F> Debug for CoroState<S, R, T, F>
where S: Unpin + Debug, R: Unpin + Debug, F: Future<Output = T> + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S, R, T, F> Freeze for CoroState<S, R, T, F>
where S: Freeze, T: Freeze, R: Freeze,

§

impl<S, R, T, F> RefUnwindSafe for CoroState<S, R, T, F>

§

impl<S, R, T, F> Send for CoroState<S, R, T, F>
where S: Send, T: Send, R: Send, F: Send,

§

impl<S, R, T, F> Sync for CoroState<S, R, T, F>
where S: Sync, T: Sync, R: Sync, F: Sync,

§

impl<S, R, T, F> Unpin for CoroState<S, R, T, F>
where T: Unpin,

§

impl<S, R, T, F> UnwindSafe for CoroState<S, R, T, 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<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.