Rust 1.75.0
blog.rust-lang.org
blog.rust-lang.org
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.
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.
All that the blog post is saying is that if you have a trait A, you can make a function where it will return something that implements A, from another trait B. It's a way to make traits depend on another. It's similar to if you have an interface called Drivable (and classes that implement it, like Car or Bike) then you can make a function like `drive` that returns something that implements Drivable, inside some other trait. All that `async fn` is is syntactic sugar for something that implements the Future trait.
Why isn’t async straightforward? It seems like a fairly fundamental aspect of a language and a key differentiator. I suppose it has something to do with capturing a reference to self, but I don’t think I understood that bit either. And why are static impl traits supported but not dynamic?
At the end of the day this feature is simply inaccessible. I’m not a complete outsider, I understand why it’s useful to return a future of result user record, or the difference between impl trait and dyn trait.
There are fairly technical answers to these questions, and people have attempted to offer them, but I suppose I would need a master class to get me to where I could understand the answers.
That isn’t the case for async in most languages and I’m not really clear why people didn’t put a bit more care into the async API for Rust.
If your language requires an expert to use a fundamental feature, I feel there is a gap in the design principles.
Does this get rid of this: https://crates.io/crates/async-trait ?