I know the code below works:
// method 1
fn vec_loop(mut v: Vec<i32>) -> Vec<i32> {
v.iter().map(|x| x * 2).collect()
}
However, I was wondering if it were possible to do it as such:
// method 2
fn vec_loop(mut v: Vec<i32>) -> Vec<i32> {
for i in v.iter_mut() {
// TODO: Fill this up so that each element in the Vec `v` is multiplied by two.
}
v
}
So far I've been unable to run the iteration using iter_mut().I'd appreciate it if:
- Someone could shed light on how to run the code in this manner.
- Shed insight into whether or not there are any performance variations between method 1 and method 2.