3 ms·
this is so cool :) one other question for async Rust experts... is it trivial to replace every use of the #[async_trait] with this, once it releases? async_tra
by andy_xor_andrew 3y ago
this is so cool :) one other question for async Rust experts...
is it trivial to replace every use of the #[async_trait] with this, once it releases? async_trait was just a macro for adding a bunch of `Box<Pin<dyn Future<Output = BlahBlah> + OtherJunk>` and so on and so on.
Is async_trait entirely obsolete now, or are there still situations where async_trait must be used, where builtin async will not?
edit: if I read one more paragraph I would have seen the answer, it's right there in the post :)
- vlovich123 3y agoFor anyone looking for a TLDR, dynamic dispatch is the major missing piece. The only other reason is if you need to support a compiler version < 1.75
- pitaj 3y agoI've seen dynamic dispatch mentioned twice. What do you mean? Isn't that just `fn foo() -> Box<dyn Future<...>>`?
- gdcbe 3y agoDynamic dispatch is where you call a method on a Box<dyn T> type, where T is a trait. Cfr: https://doc.rust-lang.org/1.8.0/book/trait-objects.html https://doc.rust-lang.org/1.8.0/book/trait-objects.html This in contrast to generics which is static.
- gdcbe 3y agoYeah and I was trying to implement their workaround for missing dynamic dispatch in a generic-heavy multithreaded async (tokio, hyper) context.., Cfr: https://github.com/plabayo/tower-async/pull/12 https://github.com/plabayo/tower-async/pull/12 So far didn’t manage to produce a box that works without everything else in my tower async stack having to need send sync trait bounds as well… and of course needing nightly ‘call(): Send’ return bounds. Despite that, haven’t found a reasonable working solution to support that in ‘tower-async’ Might be just me still having to b learn a lot. More then happy to hear feedbacks add help on these matters. And of course this is a WIP. So fully understand. Respect to the entire async wg team. Onwards and forward.
- WhyNotHugo 3y ago`#[async_trait]` does dynamic dispatch, this approach does not. If you need to use something like `Box<dyn MyTrait>`, then you'll want to continue using `#[async_trait]`.