4 ms·
This is an exciting upcoming feature in Rust, which you can read more about in a couple places: - http://aturon.github.io/blog/2015/09/28/impl-trait/ http://at
by aturon 10y ago
This is an exciting upcoming feature in Rust, which you can read more about in a couple places:
- http://aturon.github.io/blog/2015/09/28/impl-trait/ http://aturon.github.io/blog/2015/09/28/impl-trait/
- https://github.com/rust-lang/rfcs/pull/1522 https://github.com/rust-lang/rfcs/pull/1522
This feature allows you to return any struct that implements the trait, without having to type the name of the struct (which can sometimes be quite big). It also means that clients only know what traits are implemented; the concrete type is invisible to them. The above links have a bunch more detail.
(And this feature is set to land in nightly Rust very soon! Shoutout to eddyb :)
- agmcleod 10y agoSounds awesome. Love it :)
- dukerutledge 10y agoSo, existentially quantified types?
- GolDDranks 10y agoYes. However, there isn't full support of existential types in the horizon – only returning them from a function (and using them inside the caller, as the type inference allows this). This resolves some specific pain points of the current Rust experience. There may or may not be some extensions (like storing them in fields of structs) in the future. Note that Rust supported existentials before too, in the form of trait objects. But this was only possible behind a pointer and using virtual dispatch, so the performance story wasn't perfect. The impl Trait syntax is supported through monomorphization.
- dukerutledge 10y agoYeah, since rust is eager existential types seem like a necessary evil.