I have a for loop:
let list: &[i32]= vec!(1,3,4,17,81);
for el in list {
println!("The current element is {}", el);
println!("The current index is {}", i);// <- How do I get the current index?
}
How can I get the index of the current element?
I have tried
for el, i in list
for {el, i} in list
for (el, i) in list.enumerate()
I was able to access the iterator using a map of the vec, but received an error:
unused `std::iter::Map` that must be used
note: `#[warn(unused_must_use)]` on by default
note: iterators are lazy and do nothing unless consumed
, and this SO answer on the subject leads me to believe I should be using a for loop instead (though I could be misunderstanding), because I am not trying to adjust the original vec in any way.