diff options
| author | Hunter Kvalevog <hunter@kvog.sh> | 2026-09-27 12:11:32 -0500 |
|---|---|---|
| committer | Hunter Kvalevog <hunter@kvog.sh> | 2026-09-27 12:11:32 -0500 |
| commit | b9b008c1d4a730335bdc9d465b0fdf7869fb09d4 (patch) | |
| tree | e9695905445b4bab89c07b8662fe40207b74c288 /rustlings/exercises/13_error_handling/errors1.rs | |
| parent | 1da0f56d76e5d5117eac05af092bf0ab58b14c8f (diff) | |
rustlings: complete 13
Diffstat (limited to 'rustlings/exercises/13_error_handling/errors1.rs')
| -rw-r--r-- | rustlings/exercises/13_error_handling/errors1.rs | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/rustlings/exercises/13_error_handling/errors1.rs b/rustlings/exercises/13_error_handling/errors1.rs index e07fddc..b9b9bd5 100644 --- a/rustlings/exercises/13_error_handling/errors1.rs +++ b/rustlings/exercises/13_error_handling/errors1.rs @@ -4,12 +4,11 @@ // construct to `Option` that can be used to express error conditions. Change // the function signature and body to return `Result<String, String>` instead // of `Option<String>`. -fn generate_nametag_text(name: String) -> Option<String> { +fn generate_nametag_text(name: String) -> Result<String, String> { if name.is_empty() { - // Empty names aren't allowed - None + Err(String::from("Empty names aren't allowed")) } else { - Some(format!("Hi! My name is {name}")) + Ok(format!("Hi! My name is {name}")) } } |