I'm working on a dependency injection / dependency inversion framework for Rust (GitHub - Leandros/ferrunix: A simple, idiomatic, and lightweight dependency injection framework for Rust.). I'm in the process of adding fallible constructors (returning Result<T>
, instead of T
) and adding support for async closures (so users won't have to use bare boxed futures anymore, no more Box::pin(async move { ... })
).
Unfortunately, async closures don't support restricting the bounds of the future in stable Rust (in nightly this can be enabled); therefore, a workaround is required.
This workaround, generally, works, however, it seems to break type inference in rustc
(interestingly, rust analyzer can correctly infer the types).
I've created a small example, which, unfortunately, is still almost 300 lines long. The two interesting parts are the workaround AsyncCtor
and AsyncCtorLifetime
, and the invocation in main
.
Has anyone got any idea how I could convince rustc to properly infer the types? If the workaround is removed, inference works, but the actual implementation on line 92 and 93 needs to be replaced by a todo!
to see it in action.