dtolnay / async-trait

Type erasure for async trait methods
Apache License 2.0
1.81k stars 84 forks source link

Considering a different Future type than `Pin<Box<dyn Future>>` #137

Closed Matthias247 closed 2 years ago

Matthias247 commented 3 years ago

I wrote a bit on internals.rust-lang.org how a different Future type could be used to achieve type erasure + dynamic dispatch, while improving performance for some use-cases.

By using a specialized Future, allocations can for example between reused between various calls to the trait. I think there might also be other possibilities and use-cases.

Would you be interested to move async-trait to using something like DynamicFuture?

The type could live in this project, in an independent project, or eventually move into the standard library (it's essentially just another storage agnostic trait object - like Waker/RawWaker.

I think to answer this question one should also consider the follow-up question of: Could async-trait allow to influence the type of generated code via either additional attributes or plugins in order to actually make use of different future representations. But the details about this could be figured out later on in separate discussions.

dtolnay commented 2 years ago

I would prefer not to pursue this in this crate, but it would be great if someone else maintained a different crate which works that way.

Thanks anyway for the suggestion, the writeup in the forum thread, and the prototype!