summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--exercises/06_move_semantics/move_semantics1.rs3
-rw-r--r--rustlings-macros/info.toml3
-rw-r--r--solutions/06_move_semantics/move_semantics1.rs26
3 files changed, 27 insertions, 5 deletions
diff --git a/exercises/06_move_semantics/move_semantics1.rs b/exercises/06_move_semantics/move_semantics1.rs
index 8c3fe3a..4eb3d61 100644
--- a/exercises/06_move_semantics/move_semantics1.rs
+++ b/exercises/06_move_semantics/move_semantics1.rs
@@ -1,3 +1,4 @@
+// TODO: Fix the compiler error in this function.
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
let vec = vec;
@@ -17,9 +18,7 @@ mod tests {
#[test]
fn move_semantics1() {
let vec0 = vec![22, 44, 66];
-
let vec1 = fill_vec(vec0);
-
assert_eq!(vec1, vec![22, 44, 66, 88]);
}
}
diff --git a/rustlings-macros/info.toml b/rustlings-macros/info.toml
index 3edd1c6..bfe32cd 100644
--- a/rustlings-macros/info.toml
+++ b/rustlings-macros/info.toml
@@ -342,8 +342,7 @@ error on the line where we push an element to the vector, right?
The fix for this is going to be adding one keyword, and the addition is NOT on
the line where we push to the vector (where the error is).
-Also: Try accessing `vec0` after having called `fill_vec()`. See what
-happens!"""
+Try accessing `vec0` after having called `fill_vec()`. See what happens!"""
[[exercises]]
name = "move_semantics2"
diff --git a/solutions/06_move_semantics/move_semantics1.rs b/solutions/06_move_semantics/move_semantics1.rs
index 4e18198..ac34e7a 100644
--- a/solutions/06_move_semantics/move_semantics1.rs
+++ b/solutions/06_move_semantics/move_semantics1.rs
@@ -1 +1,25 @@
-// Solutions will be available before the stable release. Thank you for testing the beta version 🥰
+fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
+ let mut vec = vec;
+ // ^^^ added
+
+ vec.push(88);
+
+ vec
+}
+
+fn main() {
+ // You can optionally experiment here.
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn move_semantics1() {
+ let vec0 = vec![22, 44, 66];
+ let vec1 = fill_vec(vec0);
+ // `vec0` can't be accessed anymore because it is moved to `fill_vec`.
+ assert_eq!(vec1, vec![22, 44, 66, 88]);
+ }
+}