How to Use Higher-Ranked Trait Bounds (for<'a>) in Rust

Use `for<'a>` in trait bounds to ensure a type implements a trait for all possible lifetimes.

Use the for<'a> syntax in a trait bound to specify that a type implements a trait for all possible lifetimes, not just a specific one.

fn process<F>(f: F) 
where 
    F: for<'a> Fn(&'a str) -> &'a str 
{
    // f can accept a reference with any lifetime
}

This Higher-Ranked Trait Bound (HRTB) ensures the closure f works regardless of the lifetime of the input string slice.