[][src]Function tao_of_rust::ch11::rayon::generator

pub fn generator()

协程

Basic usage: 生成器

#![feature(generators, generator_trait)]
use std::ops::{Generator, GeneratorState};
fn main() {
    let mut generator = || {
        println!("start");
        yield 1;
        println!("back");
        return "foo"
    };
   match generator.resume() {
       GeneratorState::Yielded(1) => {println!("yield 1");}
       _ => panic!("unexpected value from resume"),
   }
   match generator.resume() {
       GeneratorState::Complete("foo") => {println!("return foo")}
       _ => panic!("unexpected value from resume"),
   }
}Run