rustlings/exercises/move_semantics/move_semantics2.rs
murasame 3cc91daba5 progress 50 percent
Change-Id: I8c926bd37d7fefc9143b0accdb1a165a9c1063df
2023-05-19 17:41:56 +08:00

28 lines
674 B
Rust

// move_semantics2.rs
// Execute `rustlings hint move_semantics2` or use the `hint` watch subcommand for a hint.
// Expected output:
// vec0 has length 3 content `[22, 44, 66]`
// vec1 has length 4 content `[22, 44, 66, 88]`
fn main() {
let mut vec0 = Vec::new();
// Do not move the following line!
fill_vec(&mut vec0);
// Do not change the following line!
println!("{} has length {} content `{:?}`", "vec0", vec0.len(), vec0);
let mut vec1 = vec0.clone();
vec1.push(88);
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
}
fn fill_vec(vec: &mut Vec<i32>) {
vec.push(22);
vec.push(44);
vec.push(66);
}