Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created November 1, 2018 12:31
Show Gist options
  • Save rust-play/c6f64a5928eaccac85650a1418ec4291 to your computer and use it in GitHub Desktop.
Save rust-play/c6f64a5928eaccac85650a1418ec4291 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
#![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