Add move_semantics 1 and 2
This commit is contained in:
parent
b71bff8509
commit
82055482e9
|
@ -3,8 +3,6 @@
|
||||||
// Execute `rustlings hint move_semantics1` or use the `hint` watch subcommand
|
// Execute `rustlings hint move_semantics1` 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];
|
||||||
|
@ -15,7 +13,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
||||||
let vec = vec;
|
let mut vec = vec;
|
||||||
|
|
||||||
vec.push(88);
|
vec.push(88);
|
||||||
|
|
||||||
|
|
|
@ -5,20 +5,18 @@
|
||||||
// Execute `rustlings hint move_semantics2` or use the `hint` watch subcommand
|
// Execute `rustlings hint move_semantics2` 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 mut vec1 = fill_vec(&vec0);
|
||||||
|
|
||||||
assert_eq!(vec0, vec![22, 44, 66]);
|
assert_eq!(vec0, vec![22, 44, 66]);
|
||||||
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: &Vec<i32>) -> Vec<i32> {
|
||||||
let mut vec = vec;
|
let mut vec = vec.to_owned();
|
||||||
|
|
||||||
vec.push(88);
|
vec.push(88);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue