jkarneges / rust-async-bench

The cost of Rust async/await
101 stars 1 forks source link

trait aliases #2

Closed jkarneges closed 2 years ago

jkarneges commented 4 years ago

Once Permit impl Trait in type aliases is stabilized, it may be possible to more ergonomically create unions of Futures and remove an unnecessary copy when spawning.

jkarneges commented 2 years ago

I attempted to implement this using nightly and failed. We only have 1 top level generated future, whose behavior is specialized via arguments, and it appears it is not possible for a generated future to refer to its own type alias. Maybe a circular dependency issue with TAIT.

However, I was able to come up with an alternative solution to ergonomics/copying by making it possible to spawn tasks via arbitrary argument values rather than by constructing actual futures. The executor is initialized with a callback function that can turn these arguments into futures. This way, the generated future doesn't have to reference its own type when trying to spawn and the circular referencing is avoided.