fix: refactor move semantics 1-4 into tests
This commit is contained in:
16
info.toml
16
info.toml
@@ -284,9 +284,9 @@ better. What do you think is the more commonly used pattern under Rust developer
|
||||
[[exercises]]
|
||||
name = "move_semantics1"
|
||||
path = "exercises/move_semantics/move_semantics1.rs"
|
||||
mode = "compile"
|
||||
mode = "test"
|
||||
hint = """
|
||||
So you've got the "cannot borrow immutable local variable `vec1` as mutable" error on the line
|
||||
So you've got the "cannot borrow immutable local variable `vec` as mutable" 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).
|
||||
@@ -296,7 +296,7 @@ Also: Try accessing `vec0` after having called `fill_vec()`. See what happens!""
|
||||
[[exercises]]
|
||||
name = "move_semantics2"
|
||||
path = "exercises/move_semantics/move_semantics2.rs"
|
||||
mode = "compile"
|
||||
mode = "test"
|
||||
hint = """
|
||||
When running this exercise for the first time, you'll notice an error about
|
||||
"borrow of moved value". In Rust, when an argument is passed to a function and
|
||||
@@ -309,16 +309,12 @@ Rust provides a couple of different ways to mitigate this issue, feel free to tr
|
||||
2. Make `fill_vec` borrow its argument instead of taking ownership of it,
|
||||
and then copy the data within the function (`vec.clone()`) in order to return an owned
|
||||
`Vec<i32>`.
|
||||
3. Or, you could make `fill_vec` *mutably* borrow a reference to its argument (which will need to be
|
||||
mutable), modify it directly, then not return anything. This means that `vec0` will change over the
|
||||
course of the function, and makes `vec1` redundant (make sure to change the parameters of the `println!`
|
||||
statements if you go this route)
|
||||
"""
|
||||
|
||||
[[exercises]]
|
||||
name = "move_semantics3"
|
||||
path = "exercises/move_semantics/move_semantics3.rs"
|
||||
mode = "compile"
|
||||
mode = "test"
|
||||
hint = """
|
||||
The difference between this one and the previous ones is that the first line
|
||||
of `fn fill_vec` that had `let mut vec = vec;` is no longer there. You can,
|
||||
@@ -328,7 +324,7 @@ an existing binding to be a mutable binding instead of an immutable one :)"""
|
||||
[[exercises]]
|
||||
name = "move_semantics4"
|
||||
path = "exercises/move_semantics/move_semantics4.rs"
|
||||
mode = "compile"
|
||||
mode = "test"
|
||||
hint = """
|
||||
Stop reading whenever you feel like you have enough direction :) Or try
|
||||
doing one step and then fixing the compiler errors that result!
|
||||
@@ -337,7 +333,7 @@ So the end goal is to:
|
||||
- so then `vec0` doesn't exist, so we can't pass it to `fill_vec`
|
||||
- `fill_vec` has had its signature changed, which our call should reflect
|
||||
- since we're not creating a new vec in `main` anymore, we need to create
|
||||
a new vec in `fill_vec`, similarly to the way we did in `main`"""
|
||||
a new vec in `fill_vec`, and fill it with the expected values"""
|
||||
|
||||
[[exercises]]
|
||||
name = "move_semantics5"
|
||||
|
||||
Reference in New Issue
Block a user