blob: b7e2ba31b59c1d9543850ac70d3bef28006326bf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#![feature(coroutines, coroutine_trait)]
#![allow(unused_assignments)]
use std::ops::{Coroutine, CoroutineState};
use std::pin::Pin;
fn main() {
let mut coroutine = || {
yield 1;
return "foo";
};
match Pin::new(&mut coroutine).resume(()) {
CoroutineState::Yielded(1) => {}
_ => panic!("unexpected value from resume"),
}
match Pin::new(&mut coroutine).resume(()) {
CoroutineState::Complete("foo") => {}
_ => panic!("unexpected value from resume"),
}
let mut coroutine = || {
yield 1;
yield 2;
yield 3;
return "foo";
};
match Pin::new(&mut coroutine).resume(()) {
CoroutineState::Yielded(1) => {}
_ => panic!("unexpected value from resume"),
}
match Pin::new(&mut coroutine).resume(()) {
CoroutineState::Yielded(2) => {}
_ => panic!("unexpected value from resume"),
}
}
|