@@ -118,6 +118,12 @@ is produced via `?`, the iterator returns `None` next.
118118
119119Similarly the ` ? ` operator on ` Option ` s will ` yield None ` if it is ` None ` , and require passing an ` Option ` to all ` yield ` operations.
120120
121+ ## Fusing
122+
123+ Just like ` Generators ` , Iterators produced by ` gen ` panic when invoked again after they have returned ` None ` once.
124+ This can probably be fixed by special casing the generator impl if ` Generator::Return = () ` , as we can trivally
125+ produce infinite values of ` () ` type.
126+
121127# Reference-level explanation
122128[ reference-level-explanation ] : #reference-level-explanation
123129## New keyword
@@ -252,13 +258,35 @@ def odd_dup(values):
252258# Unresolved questions
253259[ unresolved-questions ] : #unresolved-questions
254260
261+ ## Keyword
262+
263+ Should we use ` iter ` as a keyword instead, as we're producing ` Iterator ` s.
264+ We can also use ` gen ` like proposed in this RFC and later extend its abilities to more powerful generators.
265+
266+ [ playground] ( https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=efeacb803158c2ebd57d43b4e606c0b5 )
267+
268+ ``` rust
269+ #![feature(generators)]
270+ #![feature(iter_from_generator)]
271+
272+ fn main () {
273+ let mut it = std :: iter :: from_generator (|| {
274+ yield 1
275+ });
276+
277+ assert_eq! (it . next (), Some (1 ));
278+ assert_eq! (it . next (), None );
279+ it . next (); // panics
280+ }
281+ ```
282+
255283## Panicking
256284
257285What happens when a ` gen ` block that panicked gets ` next ` called again? Do we need to poison the iterator?
258286
259287## Fusing
260288
261- Are ` gen ` blocks fused? Or may they behave eratically after returning ` None ` the first time?
289+ Should we make ` gen ` blocks fused? Right now they'd panic (which is what the generator impl does):
262290
263291## Contextual keyword
264292
0 commit comments