2023-10-19 16:46:28 -05:00
|
|
|
#![feature(coroutines, coroutine_trait)]
|
2023-08-14 06:29:41 -05:00
|
|
|
#![allow(unused_assignments)]
|
|
|
|
|
2023-10-19 11:06:43 -05:00
|
|
|
use std::ops::{Coroutine, CoroutineState};
|
2023-08-14 06:29:41 -05:00
|
|
|
use std::pin::Pin;
|
|
|
|
|
|
|
|
fn main() {
|
2023-10-19 16:46:28 -05:00
|
|
|
let mut coroutine = || {
|
2023-08-14 06:29:41 -05:00
|
|
|
yield 1;
|
|
|
|
return "foo";
|
|
|
|
};
|
|
|
|
|
2023-10-19 16:46:28 -05:00
|
|
|
match Pin::new(&mut coroutine).resume(()) {
|
2023-10-19 11:06:43 -05:00
|
|
|
CoroutineState::Yielded(1) => {}
|
2023-08-14 06:29:41 -05:00
|
|
|
_ => panic!("unexpected value from resume"),
|
|
|
|
}
|
2023-10-19 16:46:28 -05:00
|
|
|
match Pin::new(&mut coroutine).resume(()) {
|
2023-10-19 11:06:43 -05:00
|
|
|
CoroutineState::Complete("foo") => {}
|
2023-08-14 06:29:41 -05:00
|
|
|
_ => panic!("unexpected value from resume"),
|
|
|
|
}
|
|
|
|
|
2023-10-19 16:46:28 -05:00
|
|
|
let mut coroutine = || {
|
2023-08-14 06:29:41 -05:00
|
|
|
yield 1;
|
|
|
|
yield 2;
|
|
|
|
yield 3;
|
|
|
|
return "foo";
|
|
|
|
};
|
|
|
|
|
2023-10-19 16:46:28 -05:00
|
|
|
match Pin::new(&mut coroutine).resume(()) {
|
2023-10-19 11:06:43 -05:00
|
|
|
CoroutineState::Yielded(1) => {}
|
2023-08-14 06:29:41 -05:00
|
|
|
_ => panic!("unexpected value from resume"),
|
|
|
|
}
|
2023-10-19 16:46:28 -05:00
|
|
|
match Pin::new(&mut coroutine).resume(()) {
|
2023-10-19 11:06:43 -05:00
|
|
|
CoroutineState::Yielded(2) => {}
|
2023-08-14 06:29:41 -05:00
|
|
|
_ => panic!("unexpected value from resume"),
|
|
|
|
}
|
|
|
|
}
|