#![feature(coroutines)]
#![feature(coroutine_trait)]
#![feature(stmt_expr_attributes)]
use std::ops::{Coroutine, CoroutineState};
use std::pin::Pin;
fn main() {
let mut coroutine = #[coroutine] || {
yield 1;
"foo"
};
match Pin::new(&mut coroutine).resume(()) {
CoroutineState::Yielded(1) => {
println!("yielded test");
}
_ => panic!("unexpected return from resume"),
}
match Pin::new(&mut coroutine).resume(()) {
CoroutineState::Complete("foo") => {
println!("foo test");
}
_ => panic!("unexpected return from resume"),
}
}
error[E0554]: `#![feature]` may not be used on the stable release channel
…
$ rustup install nightly
$ cargo +nightly run
Compiling parallel v0.1.0 (/home/vagrant/dev/rust/parallel)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.28s
Running `target/debug/parallel`
yielded test
foo test
use std::ops::{Coroutine, CoroutineState};
use std::pin::Pin;
fn main() {
let mut coroutine = #[coroutine] || {
println!("2");
yield;
println!("4");
};
println!("1");
Pin::new(&mut coroutine).resume(());
println!("3");
Pin::new(&mut coroutine).resume(());
println!("5");
}
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.27s
Running `target/debug/parallel`
1
2
3
4
5
Pin::new(&mut coroutine).resume(());で一旦停止するのか…