Why does Rust prevent this code from compiling, with the error: "cannot borrow immutable local variable arr as mutable"? How to pass the vector into another function as mutable reference?
let mut vec = vec![0];
fn bar(vec: &mut Vec<i32>) {
// some code here
}
fn foo(vec: &mut Vec<i32>) {
bar(&mut vec);
}
foo(&mut vec);
cannot borrow as mutable, consider changing this to be mutable