Hi there!
I'm currently trying to figure out whether there is some way to express this borrow in some way:
use std::future::Future;
use futures::future::BoxFuture; // 0.3.16
type BoxedTaskFn<A, R> = Box<
dyn for<'a> FnOnce(&'a mut A) -> BoxFuture<'a, R> + Send
>;
fn run_boxed_task<A, R>(task: BoxedTaskFn<A, R>) {
todo!()
}
fn run_task<A, R, T, F>(task: T)
where
T: for<'a> FnOnce(&'a mut A) -> F + Send + 'static,
F: Future<Output = R> + Send + 'a, // <- 'a obviously not declared here
{
todo!()
}
Essentially, I want run_task
to express the same borrow semantic as the boxed variant, but without the boxes. However, because the return value in the second variant is another type argument instead of being dyn
(where I can place the 'a
), I cannot use the HRTB lifetime 'a
in the bounds for F
. What I want to express is pretty much
T: for<'a> FnOnce(&'a mut A) -> (impl Future<Output = R> + Send + 'a) + Send + 'static
except that impl
isn't allowed in this position. Is it possible to express this somehow? My intuition is that it's not, because F
would need to be higher kinded here in order to make this work (F<'a>
)?