diff options
Diffstat (limited to 'src/doc/unstable-book/src/the-unstable-book.md')
-rw-r--r-- | src/doc/unstable-book/src/the-unstable-book.md | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/doc/unstable-book/src/the-unstable-book.md b/src/doc/unstable-book/src/the-unstable-book.md index 554c52c3c..9090b134d 100644 --- a/src/doc/unstable-book/src/the-unstable-book.md +++ b/src/doc/unstable-book/src/the-unstable-book.md @@ -5,16 +5,31 @@ each one organized by a "feature flag." That is, when using an unstable feature of Rust, you must use a flag, like this: ```rust -#![feature(box_syntax)] +#![feature(generators, generator_trait)] + +use std::ops::{Generator, GeneratorState}; +use std::pin::Pin; fn main() { - let five = box 5; + let mut generator = || { + yield 1; + return "foo" + }; + + match Pin::new(&mut generator).resume(()) { + GeneratorState::Yielded(1) => {} + _ => panic!("unexpected value from resume"), + } + match Pin::new(&mut generator).resume(()) { + GeneratorState::Complete("foo") => {} + _ => panic!("unexpected value from resume"), + } } ``` -The `box_syntax` feature [has a chapter][box] describing how to use it. +The `generators` feature [has a chapter][generators] describing how to use it. -[box]: language-features/box-syntax.md +[generators]: language-features/generators.md Because this documentation relates to unstable features, we make no guarantees that what is contained here is accurate or up to date. It's developed on a |