forked from rust-lang/rustlings
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpart4.toml
95 lines (82 loc) · 3.65 KB
/
part4.toml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
[[exercises]]
name = "move_semantics1"
path = "exercises/06_move_semantics/move_semantics1.rs"
mode = "test"
hint = """
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).
Also: Try accessing `vec0` after having called `fill_vec()`. See what
happens!"""
[[exercises]]
name = "move_semantics2"
path = "exercises/06_move_semantics/move_semantics2.rs"
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
it's not explicitly returned, you can't use the original variable anymore.
We call this "moving" a variable. When we pass `vec0` into `fill_vec`, it's
being "moved" into `vec1`, meaning we can't access `vec0` anymore after the
fact.
Rust provides a couple of different ways to mitigate this issue, feel free to
try them all:
1. You could make another, separate version of the data that's in `vec0` and
pass that to `fill_vec` instead.
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>`.
"""
[[exercises]]
name = "move_semantics3"
path = "exercises/06_move_semantics/move_semantics3.rs"
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,
instead of adding that line back, add `mut` in one place that will change
an existing binding to be a mutable binding instead of an immutable one :)"""
[[exercises]]
name = "move_semantics4"
path = "exercises/06_move_semantics/move_semantics4.rs"
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!
So the end goal is to:
- get rid of the first line in main that creates the new vector
- 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`, and fill it with the expected values"""
[[exercises]]
name = "move_semantics5"
path = "exercises/06_move_semantics/move_semantics5.rs"
mode = "test"
hint = """
Carefully reason about the range in which each mutable reference is in
scope. Does it help to update the value of referent (`x`) immediately after
the mutable reference is taken? Read more about 'Mutable References'
in the book's section 'References and Borrowing':
https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#mutable-references.
"""
[[exercises]]
name = "move_semantics6"
path = "exercises/06_move_semantics/move_semantics6.rs"
mode = "compile"
hint = """
To find the answer, you can consult the book section "References and Borrowing":
https://doc.rust-lang.org/stable/book/ch04-02-references-and-borrowing.html
The first problem is that `get_char` is taking ownership of the string. So
`data` is moved and can't be used for `string_uppercase`. `data` is moved to
`get_char` first, meaning that `string_uppercase` cannot manipulate the data.
Once you've fixed that, `string_uppercase`'s function signature will also need
to be adjusted.
Can you figure out how?
Another hint: it has to do with the `&` character."""
[[exercises]]
name = "strings4"
path = "exercises/09_strings/strings4.rs"
mode = "compile"
hint = "No hints this time ;)"