协程
Rust的协程库
[ dependencies ]
coroutine = " 0.8 "
用法
协程的基本用法
extern crate coroutine;
use std :: usize ;
use coroutine :: asymmetric :: Coroutine;
fn main () {
let coro: Coroutine < i32> = Coroutine :: spawn ( | me,_ | {
for num in 0 .. 10 {
me. yield_with (num);
}
usize :: MAX
});
for num in coro {
println! ( "{}" , num. unwrap ());
}
}