3 ms·
Inheritance is about providing business logic in all downstream inheritors through a super() chain. If you want shared logic in Rust between several implementor
by seanalltogether 4y ago
Inheritance is about providing business logic in all downstream inheritors through a super() chain. If you want shared logic in Rust between several implementors of a trait you will probably end up with duplicate code. There are drawbacks to both.
- Gigachad 4y agoYou can solve duplication with macros to implement traits. The Rust way seems to provide the same convenience without the runtime costs.
- seanalltogether 4y agoMacros provide code injection, that's not the same thing. Inheritance allows for overrides so you can have [default super logic]+[custom child logic]. That's only possible in rust with a lot of copy and paste, which can be fragile to maintain long term. Most UI frameworks are built around inheritance to guarantee logic provided by the base view or view group, while allowing for inheritors to mix in custom logic as well