Lifetime for (async) closure args / Problem with workaround: expected X found (same) X

It is actually possible to restrict lifetimes in the way you want. I read about this at Closure lifetime question and at Argument requires that ... is borrowed for 'static.

You would change your signature to:

async fn call_closure<'max, C>(mut closure: C)
where
    C: for<'a> FnMut(&'a str, [&'a &'max (); 0]) -> Pin<Box<dyn 'a + Future<Output = ()>>>

and the [&'a &'max (); 0] argument would generate an implicit bound that requires 'a to be shorter than 'max.

(Playground)

4 Likes