File tree Expand file tree Collapse file tree 2 files changed +4
-10
lines changed Expand file tree Collapse file tree 2 files changed +4
-10
lines changed Original file line number Diff line number Diff line change 1
1
// errors1.rs
2
2
// This function refuses to generate text to be printed on a nametag if
3
3
// you pass it an empty string. It'd be nicer if it explained what the problem
4
- // was, instead of just sometimes returning `None`. The 2nd test currently
5
- // does not compile or pass, but it illustrates the behavior we would like
6
- // this function to have.
4
+ // was, instead of just sometimes returning `None`. Thankfully, Rust has a similar
5
+ // construct to `Option` that can be used to express error conditions. Let's use it!
7
6
// Execute `rustlings hint errors1` for hints!
8
7
9
8
// I AM NOT DONE
@@ -21,9 +20,6 @@ pub fn generate_nametag_text(name: String) -> Option<String> {
21
20
mod tests {
22
21
use super :: * ;
23
22
24
- // This test passes initially if you comment out the 2nd test.
25
- // You'll need to update what this test expects when you change
26
- // the function under test!
27
23
#[ test]
28
24
fn generates_nametag_text_for_a_nonempty_name ( ) {
29
25
assert_eq ! (
Original file line number Diff line number Diff line change @@ -490,7 +490,7 @@ name = "errors1"
490
490
path = " exercises/error_handling/errors1.rs"
491
491
mode = " test"
492
492
hint = """
493
- `Err` is one of the variants of `Result`, so what the 2nd test is saying
493
+ `Ok` and ` Err` are one of the variants of `Result`, so what the tests are saying
494
494
is that `generate_nametag_text` should return a `Result` instead of an
495
495
`Option`.
496
496
@@ -500,9 +500,7 @@ To make this change, you'll need to:
500
500
- change the body of the function to return `Ok(stuff)` where it currently
501
501
returns `Some(stuff)`
502
502
- change the body of the function to return `Err(error message)` where it
503
- currently returns `None`
504
- - change the first test to expect `Ok(stuff)` where it currently expects
505
- `Some(stuff)`."""
503
+ currently returns `None`"""
506
504
507
505
[[exercises ]]
508
506
name = " errors2"
You can’t perform that action at this time.
0 commit comments