Add .iter_idx() and .iter_mut_idx()


#1

Iterators are useful in Rust to avoid bound checking, but sometimes an index is need. It would be useful to have iterators available which provide also an index value for each iteration. I am thinking about something like:

for (v1e, i) in v1.iter_mut_idx() {
*v1e = i;
}

A more complex example would be:

for ((v1e, i), v2e) in v1.iter_mut_idx().zip(v2.iter()) {
*v1e = v1e + v2e + i;
}


#2

See enumerate() .
20chars


#3

Check out
http://doc.rust-lang.org/nightly/std/iter/trait.Iterator.html#method.enumerate


#4

Thanks all, that’s exactly what I was looking for!