Re:Two years of Rust
by comex on Monday May 15, 2017 @05:05PM
(#14345114)
What about interfaces? The basic idea of fat pointers with vtables works the same as Rust's trait objects. If you mean the ability to dynamically cast from one interface type to another, which Rust doesn't support - that does require a global list of implemented interfaces per type, but without generics that's not too hard to implement. (In Rust, it would be drastically more complex, verging on impossible to pull off with a good UX, due to various language features including wildcard impls, type-parameterized traits, and a Turing-complete type system.)
[ Parent
| on HN ]
When ever you would need to box a trait object in Rust Go automatically performs a heap allocation that is garbaged collected at some point.
A bit more is explained here https://research.swtch.com/interfaces
Basically there are some property of Go interfaces that make them far more dynamic than traits and implementations in Rust.
> (In Rust, it would be drastically more complex, verging on impossible to pull off with a good UX, due to various language features including wildcard impls, type-parameterized traits, and a Turing-complete type system.)
Swift can downcast, and it has generic extensions and generic protocols. I highly suspect it has a Turing-complete type system as well.
Supporting this requires heroic effort in the compiler, but it can be done.