Completed exercise up to Traits
This commit is contained in:
@@ -4,12 +4,14 @@
|
||||
// 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
|
||||
// None
|
||||
Err("Empty names aren't allowed".to_string())
|
||||
} else {
|
||||
Some(format!("Hi! My name is {name}"))
|
||||
// Some(format!("Hi! My name is {name}"))
|
||||
Ok(format!("Hi! My name is {name}"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user