diff options
Diffstat (limited to 'exercises/06_move_semantics/move_semantics2.rs')
| -rw-r--r-- | exercises/06_move_semantics/move_semantics2.rs | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/exercises/06_move_semantics/move_semantics2.rs b/exercises/06_move_semantics/move_semantics2.rs index dc58be5..a3ab7a0 100644 --- a/exercises/06_move_semantics/move_semantics2.rs +++ b/exercises/06_move_semantics/move_semantics2.rs @@ -1,26 +1,28 @@ -// move_semantics2.rs -// -// Make the test pass by finding a way to keep both Vecs separate! -// -// Execute `rustlings hint move_semantics2` or use the `hint` watch subcommand -// for a hint. - -// I AM NOT DONE +fn fill_vec(vec: Vec<i32>) -> Vec<i32> { + let mut vec = vec; -#[test] -fn main() { - let vec0 = vec![22, 44, 66]; + vec.push(88); - let vec1 = fill_vec(vec0); + vec +} - assert_eq!(vec0, vec![22, 44, 66]); - assert_eq!(vec1, vec![22, 44, 66, 88]); +fn main() { + // You can optionally experiment here. } -fn fill_vec(vec: Vec<i32>) -> Vec<i32> { - let mut vec = vec; +#[cfg(test)] +mod tests { + use super::*; - vec.push(88); + // TODO: Make both vectors `vec0` and `vec1` accessible at the same time to + // fix the compiler error in the test. + #[test] + fn move_semantics2() { + let vec0 = vec![22, 44, 66]; - vec + let vec1 = fill_vec(vec0); + + assert_eq!(vec0, [22, 44, 66]); + assert_eq!(vec1, [22, 44, 66, 88]); + } } |
