I have read How to iterate a Vec<T> with the indexed position? where the answer is to use enumerate
in a for
-loop.
But if I don't use a for
-loop like this:
fn main() {
let v = vec![1; 10]
.iter()
.map(|&x| x + 1 /* + index */ ) // <--
.collect::<Vec<_>>();
print!("v{:?}", v);
}
How could I get the index in the above closure?