Lifetime bound on function return type Pin>>
⚓ Rust 📅 2025-09-11 👤 surdeus 👁️ 9I have recreated this simple example
I have a register type that has a mapping between a number to a callback function that return a future, the callback function accepts an argument Context, and Context have a lifetime
I want to bound the returned Future to the Context lifetime, since the returned future is only valid as long as the Context is valid, I don't want to make my Context 'static just for it to work
I am not sure if it is possible, how can I make my Callback generic over the Context lifetime
// something like that
type Callback = dyn Fn(Context<'a>) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>>;
it also doesn't make sense to add a lifetime to the Register type, since it would make the returned Future be bounded to the lifetime of Register and not Context
2 posts - 2 participants
🏷️ Rust_feed