mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-04 01:39:18 +00:00
Refactor generate_nametag_text to return a Result instead of an Option
This commit is contained in:
parent
43f6907aa1
commit
844dff4902
@ -9,14 +9,12 @@
|
||||
// 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> {
|
||||
pub fn generate_nametag_text(name: String) -> Result<String, &'static str> {
|
||||
if name.is_empty() {
|
||||
// Empty names aren't allowed.
|
||||
None
|
||||
Err("`name` was empty; it must be nonempty.")
|
||||
} else {
|
||||
Some(format!("Hi! My name is {}", name))
|
||||
Ok(format!("Hi! My name is {}", name))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user