pub fn generate_nametag_text<'a>(name: String) -> Result<String, &'a str > {
    if name.len() > 0 {
        Ok(format!("Hi! My name is {}", name))
    } else {
        // Empty names aren't allowed.
        Err("`name` was empty; it must be nonempty.")
    }
}
// errors1.rs
// This function refuses to generate text to be printed on a nametag if
// you pass it an empty string. It'd be nicer if it explained what the problem
// was, instead of just sometimes returning `None`. The 2nd test currently
// does not compile or pass, but it illustrates the behavior we would like
// this function to have.
// Execute `rustlings hint errors1` for hints!
errors1.rs
This function refuses to generate text to be printed on a nametag if
you pass it an empty string. It'd be nicer if it explained what the problem
was, instead of just sometimes returning `None`. The 2nd test currently
does not compile or pass, but it illustrates the behavior we would like
this function to have.
Execute `rustlings hint errors1` for hints!
errors1 . rs This function refuses to generate text to be printed on a nametag if you pass it an empty string . It ' d be nicer if it explained what the problem was instead of just sometimes returning ` None ` . The 2nd test currently does not compile or pass but it illustrates the behavior we would like this function to have . Execute ` rustlings hint errors1 ` for hints!
pub fn generate_nametag_text<'a>(name: String) -> Result<String, &'a str > {
    if name.len() > 0 {
        Ok(format!("Hi! My name is {}", name))
    } else {
        // Empty names aren't allowed.
        Err("`name` was empty; it must be nonempty.")
    }
}
pub fn generate_nametag_text < ' a > ( name : String ) -> Result < String , & ' a str > { if name . len ( ) > 0 { Ok ( format ! ( " " name ) ) } else { // Empty names aren't allowed. Err ( " " ) } }
errors1.rs
This function refuses to generate text to be printed on a nametag if
you pass it an empty string.
errors1 . rs This function refuses to generate text to be printed on a nametag if you pass it an empty string .
name
String
name
String