Completed exercise up to Traits

This commit is contained in:
Samuele Iacoponi
2026-02-01 16:38:57 +01:00
parent 9ef3441dba
commit b1b81f7e07
33 changed files with 732 additions and 71 deletions

View File

@@ -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}"))
}
}