@@ -118,6 +118,12 @@ is produced via `?`, the iterator returns `None` next.
118
118
119
119
Similarly the ` ? ` operator on ` Option ` s will ` yield None ` if it is ` None ` , and require passing an ` Option ` to all ` yield ` operations.
120
120
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
+
121
127
# Reference-level explanation
122
128
[ reference-level-explanation ] : #reference-level-explanation
123
129
## New keyword
@@ -252,13 +258,35 @@ def odd_dup(values):
252
258
# Unresolved questions
253
259
[ unresolved-questions ] : #unresolved-questions
254
260
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
+
255
283
## Panicking
256
284
257
285
What happens when a ` gen ` block that panicked gets ` next ` called again? Do we need to poison the iterator?
258
286
259
287
## Fusing
260
288
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):
262
290
263
291
## Contextual keyword
264
292
0 commit comments