Created
November 14, 2016 20:06
-
-
Save stat/0b04f31193e7e45dfc4ae905e8d76a59 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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