shouldn't that be a lifetime problem?

#why this compiles?

fn main(){
   let result;
   let string1 = "abcd";
        let string2 = "xyz";
        result = maior(string1, string2);
   println!("Resulrado = {}",result);


fn maior<'a>(x:&'a str,y:&'a str) -> &'a str{
    if x.len() > y.len(){
        return x;
    return y;

String literals have type &'static str, which means they can live "forever" (until the process ends).


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.