-
-
Save mykhailokrainik/0b507521922203879ac6c6db899eb620 to your computer and use it in GitHub Desktop.
Rust Generators
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
doc here