A generator produced by a generator function.
Generator are functions or closures which contain the yield
expressions.
Examples
use Generator;
let f = ;
let g = f;
assert!;
Methods
Advance a generator producing the next value yielded.
Unlike [Generator::resume
], this can only consume the yielded values.
Examples
use ;
let g = generate;
assert_eq!;
assert_eq!;
assert_eq!;
``
Resumes the execution of this generator.
This function will resume execution of the generator or start execution if it hasn't already. This call will return back into the generator's last suspension point, resuming execution from the latest yield
. The generator will continue executing until it either yields or returns, at which point this function will return.
Return value
The GeneratorState
enum returned from this function indicates what state the generator is in upon returning. If the Yielded
variant is returned then the generator has reached a suspension point and a value has been yielded out. Generators in this state are available for resumption at a later point.
If Complete
is returned then the generator has completely finished with the value provided. It is invalid for the generator to be resumed again.
Panics
This function may panic if it is called after the Complete
variant has been returned previously. While generator literals in the language are guaranteed to panic on resuming after Complete
, this is not guaranteed for all implementations of the Generator
.
Examples
use ;
let g = generate;
assert_eq!;
assert_eq!;
assert_eq!;
``
Trait Implementations
Clone the specified value
.
Examples
let a = 42;
let b = a;
let c = a.clone;
a += 1;
assert_eq!;
assert_eq!;
assert_eq!;
Protocols
for item in value
Construct an iterator over a generator.
Examples
let result = 0;
for n in count_numbers
assert_eq!;
format!
Debug print this generator.
Examples
use GeneratorState;
let a = generate;
println!;
``
let $out = clone
Clone a generator.
This clones the state of the generator too, allowing it to be resumed independently.
Examples
use GeneratorState;
let a = generate;
assert_eq!;
let b = a.clone;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
``