pub enum CoroState<S, R, T, F>{
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>
impl<S, R, T, F> CoroState<S, R, T, F>
Sourcepub fn is_pending(&self) -> bool
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);Sourcepub fn is_complete(&self) -> bool
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);Sourcepub fn unwrap_pending(self, f: impl Fn(S) -> R) -> ReadyCoro<S, R, T, F>
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);Trait Implementations§
Auto Trait Implementations§
impl<S, R, T, F> Freeze for CoroState<S, R, T, F>
impl<S, R, T, F> RefUnwindSafe for CoroState<S, R, T, F>
impl<S, R, T, F> Send for CoroState<S, R, T, F>
impl<S, R, T, F> Sync for CoroState<S, R, T, F>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more