2018-09-06 12:41:12 +00:00
|
|
|
// run-pass
|
|
|
|
|
2018-03-22 01:32:44 +00:00
|
|
|
#![feature(generators, generator_trait)]
|
2017-10-07 14:36:28 +00:00
|
|
|
|
2020-01-25 19:03:10 +00:00
|
|
|
use std::ops::{Generator, GeneratorState};
|
2018-10-04 18:49:38 +00:00
|
|
|
use std::pin::Pin;
|
2017-10-07 14:36:28 +00:00
|
|
|
|
|
|
|
fn foo(_: &str) -> String {
|
|
|
|
String::new()
|
|
|
|
}
|
|
|
|
|
2020-01-25 19:03:10 +00:00
|
|
|
fn bar(baz: String) -> impl Generator<(), Yield = String, Return = ()> {
|
2017-10-07 14:36:28 +00:00
|
|
|
move || {
|
|
|
|
yield foo(&baz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn foo2(_: &str) -> Result<String, ()> {
|
|
|
|
Err(())
|
|
|
|
}
|
|
|
|
|
2020-01-25 19:03:10 +00:00
|
|
|
fn bar2(baz: String) -> impl Generator<(), Yield = String, Return = ()> {
|
2017-10-07 14:36:28 +00:00
|
|
|
move || {
|
|
|
|
if let Ok(quux) = foo2(&baz) {
|
|
|
|
yield quux;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2020-01-25 19:03:10 +00:00
|
|
|
assert_eq!(
|
|
|
|
Pin::new(&mut bar(String::new())).resume(()),
|
|
|
|
GeneratorState::Yielded(String::new())
|
|
|
|
);
|
|
|
|
assert_eq!(Pin::new(&mut bar2(String::new())).resume(()), GeneratorState::Complete(()));
|
2017-10-07 14:36:28 +00:00
|
|
|
}
|