Created
November 1, 2018 12:31
-
-
Save rust-play/c6f64a5928eaccac85650a1418ec4291 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow(unused)] | |
#![feature(generators, generator_trait)] | |
use std::ops::{Generator, GeneratorState}; | |
fn main() { | |
let mut generator = || { | |
yield 1; | |
return "foo" | |
}; | |
match unsafe { generator.resume() } { | |
GeneratorState::Yielded(one) => { println!("{}", one) } | |
_ => panic!("unexpected return from resume"), | |
} | |
match unsafe { generator.resume() } { | |
GeneratorState::Complete(returned) => { println!("{}", returned)} | |
_ => panic!("unexpected return from resume"), | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment