forked from rust-lang/rustlings
-
Notifications
You must be signed in to change notification settings - Fork 1
/
part3.toml
109 lines (91 loc) · 3.72 KB
/
part3.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
[[exercises]]
name = "traits1"
path = "exercises/15_traits/traits1.rs"
mode = "test"
hint = """
A discussion about Traits in Rust can be found at:
https://doc.rust-lang.org/book/ch10-02-traits.html
"""
[[exercises]]
name = "traits2"
path = "exercises/15_traits/traits2.rs"
mode = "test"
hint = """
Notice how the trait takes ownership of `self`, and returns `Self`.
Try mutating the incoming string vector. Have a look at the tests to see
what the result should look like!
Vectors provide suitable methods for adding an element at the end. See
the documentation at: https://doc.rust-lang.org/std/vec/struct.Vec.html"""
[[exercises]]
name = "traits3"
path = "exercises/15_traits/traits3.rs"
mode = "test"
hint = """
Traits can have a default implementation for functions. Structs that implement
the trait can then use the default version of these functions if they choose not
to implement the function themselves.
See the documentation at: https://doc.rust-lang.org/book/ch10-02-traits.html#default-implementations
"""
[[exercises]]
name = "errors1"
path = "exercises/13_error_handling/errors1.rs"
mode = "test"
hint = """
`Ok` and `Err` are the two variants of `Result`, so what the tests are saying
is that `generate_nametag_text` should return a `Result` instead of an `Option`.
To make this change, you'll need to:
- update the return type in the function signature to be a `Result<String,
String>` that could be the variants `Ok(String)` and `Err(String)`
- change the body of the function to return `Ok(stuff)` where it currently
returns `Some(stuff)`
- change the body of the function to return `Err(error message)` where it
currently returns `None`"""
[[exercises]]
name = "errors2"
path = "exercises/13_error_handling/errors2.rs"
mode = "test"
hint = """
One way to handle this is using a `match` statement on
`item_quantity.parse::<i32>()` where the cases are `Ok(something)` and
`Err(something)`.
This pattern is very common in Rust, though, so there's a `?` operator that
does pretty much what you would make that match statement do for you!
Take a look at this section of the 'Error Handling' chapter:
https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html#a-shortcut-for-propagating-errors-the--operator
and give it a try!"""
[[exercises]]
name = "errors3"
path = "exercises/13_error_handling/errors3.rs"
mode = "compile"
hint = """
If other functions can return a `Result`, why shouldn't `main`? It's a fairly
common convention to return something like `Result<(), ErrorType>` from your
main function.
The unit (`()`) type is there because nothing is really needed in terms of
positive results."""
[[exercises]]
name = "errors4"
path = "exercises/13_error_handling/errors4.rs"
mode = "test"
hint = """
`PositiveNonzeroInteger::new` is always creating a new instance and returning
an `Ok` result.
It should be doing some checking, returning an `Err` result if those checks
fail, and only returning an `Ok` result if those checks determine that
everything is... okay :)"""
[[exercises]]
name = "errors6"
path = "exercises/13_error_handling/errors6.rs"
mode = "test"
hint = """
This exercise uses a completed version of `PositiveNonzeroInteger` from
errors4.
Below the line that `TODO` asks you to change, there is an example of using
the `map_err()` method on a `Result` to transform one type of error into
another. Try using something similar on the `Result` from `parse()`. You
might use the `?` operator to return early from the function, or you might
use a `match` expression, or maybe there's another way!
You can create another function inside `impl ParsePosNonzeroError` to use
with `map_err()`.
Read more about `map_err()` in the `std::result` documentation:
https://doc.rust-lang.org/std/result/enum.Result.html#method.map_err"""