4 ms·
I know a lot of people are enthusiastic about async traits, but for me, it's "We can return 'impl MyTrait' from trait methods! Finally!" There were a bunch of
by PoignardAzur 3y ago
I know a lot of people are enthusiastic about async traits, but for me, it's "We can return 'impl MyTrait' from trait methods! Finally!"
There were a bunch of instances in my code where I really wanted to specify "this trait returns an arbitrary iterator of X" instead of "this trait returns Vec<X>". It's nice to finally be able to write it that way.
- anonova 3y agoI was excited for this one to replace a bunch of single type Box<dyn Trait> returns, but there are still quite a few limitations using -> impl Trait in traits in general. It's still discouraged to use them in public APIs: https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-trait...
- dureuill 3y agoWe have to be careful when using impl trait in return position in public APIs. The opaqueness means that the consumer of the API cannot name the type and cannot store it inside of a struct (without making it generic (moving the issue one level higher), or boxing). I will consider this feature complete once we get the ability to name these opaque types, via a type alias impl trait.