Skip to content

Instantly share code, notes, and snippets.

@kenzan100
Last active December 5, 2016 17:59
Show Gist options
  • Save kenzan100/d96ab233872fe4ac6d5e6659a601140e to your computer and use it in GitHub Desktop.
Save kenzan100/d96ab233872fe4ac6d5e6659a601140e to your computer and use it in GitHub Desktop.
fn use_v() {
let mut v = make_v();
let w = &mut v;
w.push(8); // error! Cannot borrow `v` as immutable
print_v(&v); // because it is also borrowed as mutable
}
fn print_v(v: &Vec<i32>) {
println!("{}", v[0]);
}
fn make_v() -> Vec<i32> {
let v = vec![2, 4];
v
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment