What are lifetime bounds

Lifetime bounds are Rust annotations that ensure references remain valid for the required duration to prevent memory safety errors.

Lifetime bounds are annotations that tell the Rust compiler how long references must remain valid to prevent dangling pointers. They ensure that a reference does not outlive the data it points to, guaranteeing memory safety without a garbage collector.

fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
    if x.len() > y.len() { x } else { y }
}