How to iterate a Vec <T> with an indexed position?
1 answer
You can use the enumerate () function:
fn main() { let v = vec![1;10]; for (pos, e) in v.iter().enumerate() { println!("Element at position {}: {:?}", pos, e); } } +14
You can use the enumerate () function:
fn main() { let v = vec![1;10]; for (pos, e) in v.iter().enumerate() { println!("Element at position {}: {:?}", pos, e); } }