Is it possible to create a concrete Future type that wraps opaque Future types (no generics or trait objects)?
⚓ Rust 📅 2026-01-31 👤 surdeus 👁️ 1Hi
is it possible in Rust to wrap an opaque Future (async block, async fn, multiple concrete Future types) in a concrete Future type?
I need a trait to be dyn compatible but at the same time it should support to be called by async code. Therefore it cannot have async methods or contain generic parameters.
The method itself calls async function/methods which differ between implementations of that trait.
AFAIK by the restrictions of dyn compatibility the trait method must return a concrete type implementing the Future trait. But the issue is, that the wrapped Futures are opaque types and I found no way to pass them to the concrete type without trait objects or generic parameters.
One approach I initially tried was a struct accepting a function pointer retuning a Poll result, but I soon noticed that this can't work since you need to provide a closure capturing the wrapped Future and therefore the closure cannot be coerced to a function pointer.
Is there any known pattern in Rust to achieve this or is it simply impossible without using trait objects currently?
2 posts - 2 participants
🏷️ Rust_feed