rustlings icon indicating copy to clipboard operation
rustlings copied to clipboard

fix(move_semantics2): add expected output comment

Open stornquist opened this issue 2 years ago • 0 comments

You can easily get this to compile with the following code

fn main() {
    let vec0 = Vec::new();

-    let mut vec1 = fill_vec(vec0);
+    let mut vec1 = fill_vec(vec0.clone());

    // Do not change the following line!
    println!("{} has length {} content `{:?}`", "vec0", vec0.len(), vec0);

    vec1.push(88);

    println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
}

fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
    let mut vec = vec;

    vec.push(22);
    vec.push(44);
    vec.push(66);

    vec
}

which will make it compile and output

vec0 has length 0 content `[]`
vec1 has length 4 content `[22, 44, 66, 88]`

Adding the comment of expected output at least lets people know what they should be aiming for.

stornquist avatar Feb 18 '23 17:02 stornquist