Function context_bind::swap [] [src]

pub fn swap(data: usize) -> usize

Leave Co-Routine.

This function serves as both entry and exit point for a co-routine.

use context_bind::{Routine,StackSize,swap};
let mut dut = match Routine::new(StackSize::KiB8, move|| {
                         //everything here
                         //is executed on first
                         //call
 for i in 0usize.. {
     swap(i);            //yield to parent
                         //swap call ends
                         //when parent calls
                         //exec
 }
}){
    Ok(x) => x,
    Err(e) => panic!("\n\nCould not allocate stack.\n{:?}\n",e)
};
for x in 0..10 {
    let i = dut.exec(0); //run routine
                         //this function returns
                         //when routine calls `swap`
    assert_eq!(x,i);
}