summaryrefslogtreecommitdiff
path: root/exercises/error_handling/errors1.rs
diff options
context:
space:
mode:
authormokou <mokou@fastmail.com>2022-07-15 14:31:49 +0200
committermokou <mokou@fastmail.com>2022-07-15 14:31:49 +0200
commitc791cf4232fbfc313279b19b483c1adbca1c6862 (patch)
tree655ad6c9d33dab11dfd70f28d0ec29d03749a70b /exercises/error_handling/errors1.rs
parentf1c4caa37fe5027d121aec6433dee85433d9329d (diff)
parentc265b681b188ea21b3f8585e65ea363fc02c4b50 (diff)
Merge branch '5.0-dev'
Diffstat (limited to 'exercises/error_handling/errors1.rs')
-rw-r--r--exercises/error_handling/errors1.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/exercises/error_handling/errors1.rs b/exercises/error_handling/errors1.rs
index c417fb2..bcee972 100644
--- a/exercises/error_handling/errors1.rs
+++ b/exercises/error_handling/errors1.rs
@@ -3,16 +3,16 @@
// you pass it an empty string. It'd be nicer if it explained what the problem
// was, instead of just sometimes returning `None`. Thankfully, Rust has a similar
// construct to `Option` that can be used to express error conditions. Let's use it!
-// Execute `rustlings hint errors1` for hints!
+// Execute `rustlings hint errors1` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE
pub fn generate_nametag_text(name: String) -> Option<String> {
- if name.len() > 0 {
- Some(format!("Hi! My name is {}", name))
- } else {
+ if name.is_empty() {
// Empty names aren't allowed.
None
+ } else {
+ Some(format!("Hi! My name is {}", name))
}
}