Lifetime Bounds on Traits

Updated

October 31, 2026

Lifetime Bounds on Traits

Constrain types with lifetime bounds, such as T: 'a (meaning T must outlive lifetime 'a):

use std::fmt::Display;

fn print_ref<'a, T>(item: &'a T)
where
    T: Display + 'a,
{
    println!("Item: {}", item);
}