How to Use Higher-Ranked Trait Bounds (HRTBs) in Rust

Use the `for<'a>` syntax before a trait bound to require a type to implement that trait for all possible lifetimes.

Use Higher-Ranked Trait Bounds (HRTBs) by prefixing a trait bound with for<'a> to require a type to implement a trait for all possible lifetimes 'a. This is essential when a closure or function pointer must accept references of any lifetime.

fn process<F>(f: F) where F: for<'a> Fn(&'a str) {
    f("hello");
}