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");
}
HRTBs ensure a function or closure can work with references of any lifetime, not just one specific duration. Think of it as a universal adapter that fits any size of socket, rather than a plug designed for only one specific outlet. You use this when writing generic code that needs to accept callbacks handling temporary or long-lived data equally.