I'm trying to swap the elements inside a loop.
fn foo(nums: &mut Vec<i32>) { let mut i: usize = 0; for (j, n) in nums.iter_mut().enumerate() { if n != &0 { // swap nums[i] and nums[j]; i = i + 1; } } } But I keep getting the same error (along cannot borrow mutable nums multiple times). What am I doing wrong?
swapmethod help you doc.rust-lang.org/std/primitive.slice.html#method.swap ?