Re:Zero-cost futures in Rust
by dukerutledge on Thursday August 11, 2016 @01:40PM
(#12270225)
So, existentially quantified types?
Re:Zero-cost futures in Rust
by GolDDranks on Thursday August 11, 2016 @01:58PM
(#12270358)
Yes. 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.
Re:Zero-cost futures in Rust
by dukerutledge on Thursday August 11, 2016 @02:00PM
(#12270379)
Yeah, since rust is eager existential types seem like a necessary evil.
- http://aturon.github.io/blog/2015/09/28/impl-trait/ - 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 :)