can a function have its own lifetime?
Functions don't have lifetimes; references do. But you can have a reference to a function. And you can have a lifetime as a parameter of a function.
couldn't understand what lifetime 'a
could mean here.
It just means it's a mutably borrowed parameter of closure with lifetime &'a
.
In essence, async fn wrapper<F, Fut>(f: F)
behaves the same, since &' a
can be elided.
It would be useful if, somewhere inside the function's code, you needed to say lifetime 'a
will outlive some lifetime 'b
.
For example:
async fn wrapper<'a, 'b, F, Fut>(f: F, b: &'b Hi)
where
Fut: Future<Output = ()>,
F: FnOnce(&'a mut Hi) -> Fut,
'a : 'b