How do lifetimes work with trait objects

Trait objects in Rust automatically handle lifetimes through the reference they contain, requiring no explicit annotation.

Trait objects (dyn Trait) do not require explicit lifetime annotations because the reference inside the object carries its own lifetime.

fn process(obj: &dyn std::fmt::Display) {
    println!("{obj}");
}

The compiler infers the lifetime of the reference & automatically, ensuring the data behind the trait object outlives the function call.