mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-10 12:49:18 +00:00
adding else condtions
This commit is contained in:
parent
915c53be64
commit
d748cd156f
@ -5,14 +5,14 @@
|
||||
// construct to `Option` that can be used to express error conditions. Let's use it!
|
||||
// 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,String> {
|
||||
if name.is_empty() {
|
||||
// Empty names aren't allowed.
|
||||
None
|
||||
Err("`name` was empty; it must be nonempty.".into())
|
||||
} else {
|
||||
Some(format!("Hi! My name is {}", name))
|
||||
Ok(format!("Hi! My name is {}", name))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user