rustlings

solving rustlings ft. dracuxan
git clone [email protected]:dracuxan/rustlings.git
Log | Files | Refs

lifetimes2.rs (417B)


      1 // Don't change this function.
      2 fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
      3     if x.len() > y.len() { x } else { y }
      4 }
      5 
      6 fn main() {
      7     // TODO: Fix the compiler error by moving one line.
      8 
      9     let string1 = String::from("long string is long");
     10     let string2 = String::from("xyz");
     11     let result;
     12     {
     13         result = longest(&string1, &string2);
     14     }
     15     println!("The longest string is '{result}'");
     16 }