Refactor fill_vec function to accept a mutable reference

This commit is contained in:
Rock070 2023-12-17 16:17:24 +08:00
parent 1c51ad049f
commit a898c058fc

View File

@ -6,19 +6,17 @@
// Execute `rustlings hint move_semantics3` or use the `hint` watch subcommand // Execute `rustlings hint move_semantics3` or use the `hint` watch subcommand
// for a hint. // for a hint.
// I AM NOT DONE
#[test] #[test]
fn main() { fn main() {
let vec0 = vec![22, 44, 66]; let vec0 = vec![22, 44, 66];
let mut vec1 = fill_vec(vec0); let vec1 = fill_vec(&mut vec0.clone());
assert_eq!(vec1, vec![22, 44, 66, 88]); assert_eq!(vec1, vec![22, 44, 66, 88]);
} }
fn fill_vec(vec: Vec<i32>) -> Vec<i32> { fn fill_vec(vec: &mut Vec<i32>) -> Vec<i32> {
vec.push(88); vec.push(88);
vec vec.to_vec()
} }