rust/src/test/ui/generator/issue-44197.rs

34 lines
713 B
Rust
Raw Normal View History

// run-pass
2018-03-21 18:32:44 -07:00
#![feature(generators, generator_trait)]
use std::ops::{ Generator, GeneratorState };
2018-10-04 20:49:38 +02:00
use std::pin::Pin;
fn foo(_: &str) -> String {
String::new()
}
fn bar(baz: String) -> impl Generator<Yield = String, Return = ()> {
move || {
yield foo(&baz);
}
}
fn foo2(_: &str) -> Result<String, ()> {
Err(())
}
fn bar2(baz: String) -> impl Generator<Yield = String, Return = ()> {
move || {
if let Ok(quux) = foo2(&baz) {
yield quux;
}
}
}
fn main() {
2018-10-04 20:49:38 +02: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(()));
}