3 ms·
This is also how Go does it. It looks like Rust traits can do everything Go interfaces can do, and more?
by skybrian 12y ago
This is also how Go does it. It looks like Rust traits can do everything Go interfaces can do, and more?
- pcwalton 12y agoMore or less, yeah. The main missing features are that downcasting isn't implemented at present (since Rust's other features remove the need for most of it), and implementation is explicit instead of implicit (a design decision which I've elaborated on in the past).
- keeperofdakeys 12y agoThere are some key differences, like Rust traits using generics, and Go interfaces using an empty interface for generic code.
- Manishearth 12y agoGo's interfaces have these additional features: - They auto-implement on types that have the appropriate methods (a feature that probably is unwanted in Rust) - They can be runtime downcasted via `.(type_name_here)` - They can be runtime type switched via `switch foo.(type)` I'm not sure of the vtable internals though.