Skip to content

Instantly share code, notes, and snippets.

@stat
Created November 14, 2016 20:06
Show Gist options
  • Select an option

  • Save stat/0b04f31193e7e45dfc4ae905e8d76a59 to your computer and use it in GitHub Desktop.

Select an option

Save stat/0b04f31193e7e45dfc4ae905e8d76a59 to your computer and use it in GitHub Desktop.
fn mutate_vector(v: &mut Vec<i32>) {
// is this correct? &*v seems dirty but is required
// due to the function header...
for i in &*v {
// do something
}
v.push(32);
}
#[test]
fn mutate_vector_test() {
let mut v = vec![1, 2, 3];
mutate_vector(&mut v);
assert_eq!(4, v.len());
assert_eq!(32, v[v.len() - 1]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment