Skip to content

Commit be65710

Browse files
yllmisyllmis
authored andcommitted
update
1 parent 0efe0c4 commit be65710

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

exercises/error_handling/errors1.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
// Execute `rustlings hint errors1` or use the `hint` watch subcommand for a
1010
// hint.
1111

12-
// I AM NOT DONE
1312

14-
pub fn generate_nametag_text(name: String) -> Option<String> {
13+
14+
pub fn generate_nametag_text(name: String) -> Result<String, String> {
1515
if name.is_empty() {
1616
// Empty names aren't allowed.
17-
None
17+
Err("`name` was empty; it must be nonempty.".into())
1818
} else {
19-
Some(format!("Hi! My name is {}", name))
19+
Ok(format!("Hi! My name is {}", name))
2020
}
2121
}
2222

exercises/error_handling/errors2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
// Execute `rustlings hint errors2` or use the `hint` watch subcommand for a
2020
// hint.
2121

22-
// I AM NOT DONE
22+
2323

2424
use std::num::ParseIntError;
2525

2626
pub fn total_cost(item_quantity: &str) -> Result<i32, ParseIntError> {
2727
let processing_fee = 1;
2828
let cost_per_item = 5;
29-
let qty = item_quantity.parse::<i32>();
29+
let qty = item_quantity.parse::<i32>()?;
3030

3131
Ok(qty * cost_per_item + processing_fee)
3232
}

0 commit comments

Comments
 (0)