summaryrefslogtreecommitdiff
path: root/rustlings/exercises/13_error_handling/errors1.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rustlings/exercises/13_error_handling/errors1.rs')
-rw-r--r--rustlings/exercises/13_error_handling/errors1.rs7
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}"))
}
}