https://doc.rust-lang.org/reference/trait-bounds.html#higher-ranked-trait-bounds

Higher-Rank Trait Bounds (HRTBs) in Rust are used when you need to express that a trait bound applies to all possible lifetimes, not just one. This is particularly useful when working with closures and function pointers that can be called with references of any lifetime. Here’s when you might use HRTBs:

  1. Closures and Function Pointers: When you have a struct or function that stores a closure or function pointer, and you want to call it with references that could have any lifetime, you use HRTBs to indicate that the closure or function can be called with a reference of any lifetime

  2. Iterators: If you’re working with iterators and you want to specify that the item type of the iterator can be a reference with any lifetime, HRTBs allow you to do so. This ensures that the iterator can be used in a variety of contexts without lifetime conflicts

  3. Trait Objects: When creating trait objects that involve lifetimes, HRTBs can be used to specify that the trait object can be made from references with any lifetime, making the trait object more flexible

  4. Generic Functions: In generic functions, when you want to accept a parameter that implements a trait for all lifetimes, HRTBs let you express this requirement. [This is common with traits like FnFnMut, and FnOnce](<https://doc.rust-lang.org/nomicon/hrtb.html>)

Here’s an example of HRTBs in use:

fn call_with_ref<F>(closure: F)
where
    for<'a> F: Fn(&'a u8),
{
    let value = 10;
    closure(&value);
}

In this function, F is a type that implements Fn(&'a u8) for all choices of 'a, thanks to the HRTB for<'a>. This means closure can be called with a reference to a u8 with any lifetime, not just a specific one.

HRTBs are a more advanced feature of Rust’s type system, and they’re used when you need this level of flexibility with lifetimes and trait bounds.