a-range icon indicating copy to clipboard operation
a-range copied to clipboard

Add `.iter` method on `Range`

Open killercup opened this issue 7 years ago • 3 comments

  • [ ] for i in a_range::from(1).up_to(5).iter() { let _i: &i32 = i; } compiles
  • [ ] Tests added as doc tests on iter() method

killercup avatar Oct 19 '18 11:10 killercup

The way I understood, you want an IntoIterator implementation for &Range<Idx, Upwards>, so that for &i in &a_range::from(1).up_to(5) {} compiles.

But isn't it unnecessary since Range does not really store any value?

rnbguy avatar Oct 21 '18 18:10 rnbguy

I want to have a way to iterate over a range without it being consumed. Implementing IntoIterator on a reference is one way to do it. And this implementation could call .iter().

But isn't it unnecessary since Range does not really store any value?

I'm not sure I understand. Range has three fields. The index types may be arbitrarily complex, including internal mutability.

Am 21.10.2018 um 20:55 schrieb Ranadeep Biswas [email protected]:

The way I understood, you want an IntoIterator implementation for &Range<Idx, Upwards>, so that for &i in &a_range::from(1).up_to(5) {} compiles.

But isn't it unnecessary since Range does not really store any value?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

killercup avatar Oct 21 '18 19:10 killercup

I meant unnecessary as in there is nothing to be consumed stored in Range. Even Rust's std::ops::Range does not have .iter() implemented. Can you give one example why you would want that?

rnbguy avatar Oct 22 '18 13:10 rnbguy