pub struct Coroutine { /* private fields */ }Expand description
Two cooperating value streams that yield by alternating between lanes.
Models symmetric coroutine control: each Coroutine::resume hands control
to the next lane, falling through to the other when one is drained.
§Examples
use sim_kernel::{Ref, Symbol};
use sim_lib_control::{Coroutine, CoroutineLane, CoroutineStep};
let a = Ref::Symbol(Symbol::new("a"));
let b = Ref::Symbol(Symbol::new("b"));
let mut co = Coroutine::alternating(vec![a.clone()], vec![b.clone()]);
assert_eq!(
co.resume(),
CoroutineStep::Yielded { lane: CoroutineLane::First, value: a }
);
assert_eq!(
co.resume(),
CoroutineStep::Yielded { lane: CoroutineLane::Second, value: b }
);
assert_eq!(co.resume(), CoroutineStep::Exhausted);Implementations§
Source§impl Coroutine
impl Coroutine
Sourcepub fn alternating(first: Vec<Ref>, second: Vec<Ref>) -> Self
pub fn alternating(first: Vec<Ref>, second: Vec<Ref>) -> Self
Builds a coroutine that alternates yields between the first and
second lanes, starting with the first.
Sourcepub fn resume(&mut self) -> CoroutineStep
pub fn resume(&mut self) -> CoroutineStep
Resumes the coroutine, yielding the next value from the active lane (or
the other lane if the active one is drained), or
CoroutineStep::Exhausted when both are empty.
Trait Implementations§
impl Eq for Coroutine
impl StructuralPartialEq for Coroutine
Auto Trait Implementations§
impl Freeze for Coroutine
impl RefUnwindSafe for Coroutine
impl Send for Coroutine
impl Sync for Coroutine
impl Unpin for Coroutine
impl UnsafeUnpin for Coroutine
impl UnwindSafe for Coroutine
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