Files
rustlings/exercises/16_lifetimes/lifetimes2.rs
T

17 lines
417 B
Rust
Raw Normal View History

2026-03-12 20:54:14 -04:00
// Don't change this function.
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
2026-03-23 03:36:33 -04:00
if x.len() > y.len() { x } else { y }
2026-03-12 20:54:14 -04:00
}
fn main() {
// TODO: Fix the compiler error by moving one line.
let string1 = String::from("long string is long");
2026-03-23 03:36:33 -04:00
let string2 = String::from("xyz");
2026-03-12 20:54:14 -04:00
let result;
{
result = longest(&string1, &string2);
}
println!("The longest string is '{result}'");
}