Add .iter_idx() and .iter_mut_idx()

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;
}

See enumerate() .
20chars

1 Like

Check out

1 Like

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