Like this code:
use std::future::Future;
use std::pin::Pin;
trait A {
fn handle<'a>(&'a self, data: &'a i32) -> Pin<Box<dyn 'a + Future<Output = ()>>>;
}
impl<'b, Fut> A for fn(&'b i32) -> Fut
where
Fut: 'b + Future<Output = ()>,
{
fn handle<'a>(&'a self, data: &'a i32) -> Pin<Box<dyn 'a + Future<Output = ()>>> {
Box::pin(self(data))
}
}
how can I implement A
for all async fn(&i32)
?
This code should works:
then we can use
for<'a> A<'a>
to delegate async function everywhere.