2018-09-06 07:41:12 -05:00
|
|
|
// run-pass
|
|
|
|
|
2023-10-19 16:46:28 -05:00
|
|
|
#![feature(coroutines, coroutine_trait)]
|
2017-10-07 09:36:28 -05:00
|
|
|
|
2023-10-19 11:06:43 -05:00
|
|
|
use std::ops::{Coroutine, CoroutineState};
|
2018-10-04 13:49:38 -05:00
|
|
|
use std::pin::Pin;
|
2017-10-07 09:36:28 -05:00
|
|
|
|
|
|
|
fn foo(_: &str) -> String {
|
|
|
|
String::new()
|
|
|
|
}
|
|
|
|
|
2023-10-19 11:06:43 -05:00
|
|
|
fn bar(baz: String) -> impl Coroutine<(), Yield = String, Return = ()> {
|
2017-10-07 09:36:28 -05:00
|
|
|
move || {
|
|
|
|
yield foo(&baz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn foo2(_: &str) -> Result<String, ()> {
|
|
|
|
Err(())
|
|
|
|
}
|
|
|
|
|
2023-10-19 11:06:43 -05:00
|
|
|
fn bar2(baz: String) -> impl Coroutine<(), Yield = String, Return = ()> {
|
2017-10-07 09:36:28 -05:00
|
|
|
move || {
|
|
|
|
if let Ok(quux) = foo2(&baz) {
|
|
|
|
yield quux;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2020-01-25 13:03:10 -06:00
|
|
|
assert_eq!(
|
|
|
|
Pin::new(&mut bar(String::new())).resume(()),
|
2023-10-19 11:06:43 -05:00
|
|
|
CoroutineState::Yielded(String::new())
|
2020-01-25 13:03:10 -06:00
|
|
|
);
|
2023-10-19 11:06:43 -05:00
|
|
|
assert_eq!(Pin::new(&mut bar2(String::new())).resume(()), CoroutineState::Complete(()));
|
2017-10-07 09:36:28 -05:00
|
|
|
}
|