summaryrefslogtreecommitdiff
path: root/exercises/move_semantics
diff options
context:
space:
mode:
Diffstat (limited to 'exercises/move_semantics')
-rw-r--r--exercises/move_semantics/move_semantics1.rs19
-rw-r--r--exercises/move_semantics/move_semantics2.rs26
-rw-r--r--exercises/move_semantics/move_semantics3.rs22
-rw-r--r--exercises/move_semantics/move_semantics4.rs27
-rw-r--r--exercises/move_semantics/move_semantics5.rs9
-rw-r--r--exercises/move_semantics/move_semantics6.rs5
6 files changed, 51 insertions, 57 deletions
diff --git a/exercises/move_semantics/move_semantics1.rs b/exercises/move_semantics/move_semantics1.rs
index aac6dfc..e063937 100644
--- a/exercises/move_semantics/move_semantics1.rs
+++ b/exercises/move_semantics/move_semantics1.rs
@@ -1,26 +1,23 @@
// move_semantics1.rs
-// Execute `rustlings hint move_semantics1` or use the `hint` watch subcommand for a hint.
+//
+// Execute `rustlings hint move_semantics1` or use the `hint` watch subcommand
+// for a hint.
// I AM NOT DONE
+#[test]
fn main() {
- let vec0 = Vec::new();
+ let vec0 = vec![22, 44, 66];
let vec1 = fill_vec(vec0);
- println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
-
- vec1.push(88);
-
- println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
+ assert_eq!(vec1, vec![22, 44, 66, 88]);
}
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
- let mut vec = vec;
+ let vec = vec;
- vec.push(22);
- vec.push(44);
- vec.push(66);
+ vec.push(88);
vec
}
diff --git a/exercises/move_semantics/move_semantics2.rs b/exercises/move_semantics/move_semantics2.rs
index 68dbf02..baf6bcc 100644
--- a/exercises/move_semantics/move_semantics2.rs
+++ b/exercises/move_semantics/move_semantics2.rs
@@ -1,32 +1,26 @@
// move_semantics2.rs
-// Make me compile without changing line 13 or moving line 10!
-// 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]`
+//
+// Make the test pass by finding a way to keep both Vecs separate!
+//
+// Execute `rustlings hint move_semantics2` or use the `hint` watch subcommand
+// for a hint.
// I AM NOT DONE
+#[test]
fn main() {
- let vec0 = Vec::new();
+ let vec0 = vec![22, 44, 66];
let mut vec1 = fill_vec(vec0);
- // 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);
+ assert_eq!(vec0, vec![22, 44, 66]);
+ assert_eq!(vec1, vec![22, 44, 66, 88]);
}
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
let mut vec = vec;
- vec.push(22);
- vec.push(44);
- vec.push(66);
+ vec.push(88);
vec
}
diff --git a/exercises/move_semantics/move_semantics3.rs b/exercises/move_semantics/move_semantics3.rs
index eaa30e3..69e564a 100644
--- a/exercises/move_semantics/move_semantics3.rs
+++ b/exercises/move_semantics/move_semantics3.rs
@@ -1,26 +1,24 @@
// move_semantics3.rs
-// Make me compile without adding new lines-- just changing existing lines!
-// (no lines with multiple semicolons necessary!)
-// Execute `rustlings hint move_semantics3` or use the `hint` watch subcommand for a hint.
+//
+// Make me compile without adding new lines-- just changing existing lines! (no
+// lines with multiple semicolons necessary!)
+//
+// Execute `rustlings hint move_semantics3` or use the `hint` watch subcommand
+// for a hint.
// I AM NOT DONE
+#[test]
fn main() {
- let vec0 = Vec::new();
+ let vec0 = vec![22, 44, 66];
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);
+ assert_eq!(vec1, vec![22, 44, 66, 88]);
}
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
- vec.push(22);
- vec.push(44);
- vec.push(66);
+ vec.push(88);
vec
}
diff --git a/exercises/move_semantics/move_semantics4.rs b/exercises/move_semantics/move_semantics4.rs
index 99834ec..80b49db 100644
--- a/exercises/move_semantics/move_semantics4.rs
+++ b/exercises/move_semantics/move_semantics4.rs
@@ -1,30 +1,29 @@
// move_semantics4.rs
-// Refactor this code so that instead of passing `vec0` into the `fill_vec` function,
-// the Vector gets created in the function itself and passed back to the main
-// function.
-// Execute `rustlings hint move_semantics4` or use the `hint` watch subcommand for a hint.
+//
+// Refactor this code so that instead of passing `vec0` into the `fill_vec`
+// function, the Vector gets created in the function itself and passed back to
+// the main function.
+//
+// Execute `rustlings hint move_semantics4` or use the `hint` watch subcommand
+// for a hint.
// I AM NOT DONE
+#[test]
fn main() {
- let vec0 = Vec::new();
+ let vec0 = vec![22, 44, 66];
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);
+ assert_eq!(vec1, vec![22, 44, 66, 88]);
}
-// `fill_vec()` no longer takes `vec: Vec<i32>` as argument
+// `fill_vec()` no longer takes `vec: Vec<i32>` as argument - don't change this!
fn fill_vec() -> Vec<i32> {
+ // Instead, let's create and fill the Vec in here - how do you do that?
let mut vec = vec;
- vec.push(22);
- vec.push(44);
- vec.push(66);
+ vec.push(88);
vec
}
diff --git a/exercises/move_semantics/move_semantics5.rs b/exercises/move_semantics/move_semantics5.rs
index 36eae12..68db09e 100644
--- a/exercises/move_semantics/move_semantics5.rs
+++ b/exercises/move_semantics/move_semantics5.rs
@@ -1,7 +1,10 @@
// move_semantics5.rs
-// Make me compile only by reordering the lines in `main()`, but without
-// adding, changing or removing any of them.
-// Execute `rustlings hint move_semantics5` or use the `hint` watch subcommand for a hint.
+//
+// Make me compile only by reordering the lines in `main()`, but without adding,
+// changing or removing any of them.
+//
+// Execute `rustlings hint move_semantics5` or use the `hint` watch subcommand
+// for a hint.
// I AM NOT DONE
diff --git a/exercises/move_semantics/move_semantics6.rs b/exercises/move_semantics/move_semantics6.rs
index eb52a84..cace4ca 100644
--- a/exercises/move_semantics/move_semantics6.rs
+++ b/exercises/move_semantics/move_semantics6.rs
@@ -1,6 +1,9 @@
// move_semantics6.rs
-// Execute `rustlings hint move_semantics6` or use the `hint` watch subcommand for a hint.
+//
// You can't change anything except adding or removing references.
+//
+// Execute `rustlings hint move_semantics6` or use the `hint` watch subcommand
+// for a hint.
// I AM NOT DONE