▲ 5 r/rust
I am trying to box AsyncFn to dyn type in this way:
fn box_it(
f: impl AsyncFn() -> usize + 'static,
) -> Box<dyn Fn() -> Pin<Box<dyn Future<Output = usize>>> + 'static> {
// let res = Box<dyn Fn() -> Pin<Box<dyn Future<Output = usize>>> + 'static>;
Box::new(|| {
let fut = f();
Box::pin(async { fut.await })
})
}
However, there's a problem. Future in AsyncFn might have non 'static lifetime. Is there any way to write a type constraint which limits this?
u/ArtisticHamster — 16 days ago