Lifetime annotation
fn main() { let a = "hello"; let b = String::from("world"); let c = longer(a, b.as_str()); println!("c: {}", c); } fn longer<'a>(x: &'a str, y: &'a str) -> &'a str { if x.len() > y.len() { x } else { y } }
c: world
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
fn main() { let a = "hello"; let b = String::from("world"); let c = longer(a, b.as_str()); println!("c: {}", c); } fn longer<'a>(x: &'a str, y: &'a str) -> &'a str { if x.len() > y.len() { x } else { y } }
c: world