mismatched types
expected associated type `<for<'_> fn(&mut structs::Context) -> impl futures::Future<Output = ()> {index} as FnOnce<(&mut structs::Context,)>>::Output`
found associated type `<for<'_> fn(&mut structs::Context) -> impl futures::Future<Output = ()> {index} as FnOnce<(&mut structs::Context,)>>::Output`
the required lifetime does not necessarily outlive the static lifetimerustcE0308
get.rs(101, 32): the lifetime requirement is introduced here
The issue is I am using mutable reference Fn(&mut Context) & rust unable to get the lifetime.
Thank you
I'll assume you're currently using the solution from your last question. The problem is that every callback is required to return a Future + 'static, but any async function that captures an &'a mut Context can only return a Future + 'a (since the future must store the reference). This is what results in the compiler error: it's saying that the opaque future type corresponding to index is not 'static.
Unfortunately, the fix for this is somewhat involved. We want to assert that the callback returns a Future + 'a when given an &'a mut Context, for any lifetime 'a. This can be done with a higher-rank trait bound. But since the future type is distinct from the callback type, we must add a helper Callback<'a> trait, which asserts that a function has type Fn(&'a mut Context) -> impl Future + 'a. Altogether, it looks something like this (Rust Playground):