use std::future::Future;
struct A;
async fn foo<T, R>(t: T)
where
T: Fn(&mut A) -> R + Send + Sync + 'static,
R: Future + Send,
R::Output: Send
{
tokio::spawn(bar(t));
}
async fn bar<T, R>(t: T)
where
T: Fn(&mut A) -> R + Send,
R: Future + Send,
R::Output: Send
{
let mut a = A;
t(&mut a).await;
}
Playground : https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=e8885b0f86a5b6defcbd2f45d8e35178
My instinct is that R only need to live as long as &mut A. But this is somehow not correct.
My goal is to provide a function that accept following code
async fn handle(&mut A) {
todo!()
}
async fn main() {
foo(handle).await
}