HRTB on multiple generics

Note that using a closure won't work out that well because Rust is bad at inferring the most general bounds required for closures.

You can help Rust along with this,

print_func_result({
    fn enforce_bounds<F: FnOnce(&str) -> &str>(f: F) -> F { f }
    enforce_bounds(|x| accept_me(x))
});

But this is rather ugly. If you can, try and avoid these higher rank bounds. Especially when dealing with closures.

3 Likes