mirror of https://github.com/rust-lang/rustlings
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
678 B
Rust
44 lines
678 B
Rust
7 years ago
|
// move_semantics1.rs
|
||
9 years ago
|
// Make me compile! Scroll down for hints :)
|
||
|
|
||
6 years ago
|
fn main() {
|
||
9 years ago
|
let vec0 = Vec::new();
|
||
|
|
||
|
let vec1 = fill_vec(vec0);
|
||
|
|
||
|
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
||
|
|
||
|
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
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
7 years ago
|
// So you've got the "cannot borrow immutable local variable `vec1` as mutable" error on line 11,
|
||
|
// right? The fix for this is going to be adding one keyword, and the addition is NOT on line 11
|
||
9 years ago
|
// where the error is.
|