mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-06 18:59:19 +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
|
// Execute `rustlings hint errors1` or use the `hint` watch subcommand for a
|
||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
pub fn generate_nametag_text(name: String) -> Result<String, &'static str> {
|
||||||
|
|
||||||
pub fn generate_nametag_text(name: String) -> Option<String> {
|
|
||||||
if name.is_empty() {
|
if name.is_empty() {
|
||||||
// Empty names aren't allowed.
|
// Empty names aren't allowed.
|
||||||
None
|
Err("`name` was empty; it must be nonempty.")
|
||||||
} else {
|
} else {
|
||||||
Some(format!("Hi! My name is {}", name))
|
Ok(format!("Hi! My name is {}", name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user