1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2025-06-19 00:17:42 +02:00
Files
exercises
enums
error_handling
functions
if
macros
modules
move_semantics
README.md
move_semantics1.rs
move_semantics2.rs
move_semantics3.rs
move_semantics4.rs
primitive_types
standard_library_types
strings
structs
tests
threads
variables
test1.rs
test2.rs
test3.rs
test4.rs
src
tests
.clog.toml
.editorconfig
.gitignore
.travis.yml
CHANGELOG.md
CONTRIBUTING.md
Cargo.lock
Cargo.toml
LICENSE
README.md
default_out.txt
info.toml
install.ps1
install.sh
rustlings/exercises/move_semantics/move_semantics4.rs

31 lines
732 B
Rust
Raw Normal View History

2018-02-21 22:09:53 -08:00
// move_semantics4.rs
// Refactor this code so that instead of having `vec0` and creating the vector
// in `fn main`, we instead create it within `fn fill_vec` and transfer the
// freshly created vector from fill_vec to its caller.
// Execute `rustlings hint move_semantics4` for hints!
// I AM NOT DONE
2018-11-09 20:31:14 +01:00
fn main() {
let vec0 = Vec::new();
let mut vec1 = fill_vec(vec0);
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
vec1.push(88);
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
}
// `fill_vec()` no longer take `vec: Vec<i32>` as argument
fn fill_vec() -> Vec<i32> {
let mut vec = vec;
vec.push(22);
vec.push(44);
vec.push(66);
vec
}