logoalt Hacker News

Nine Ways to Do Inheritance in Rust, a Language Without Inheritance

70 pointsby pjmlplast Wednesday at 1:29 PM15 commentsview on HN

Comments

iTokiotoday at 7:24 AM

I almost never use inheritance beside using some kind of interfaces/traits to declare a contract.

However, the only time where I’m missing code/data reuse through inheritance is with GUI. Some mostly flat hierarchies of widgets are really powerful ways to declare and compose UI components with shared behaviors.

In rust, the DX for GUI components is always lacking compared to web, C#. With maybe the exception of Slint which is really not Rust anymore.

Is there a way to have good DX for GUI components in Rust?

show 2 replies
pdpitoday at 5:32 AM

Cool catalogue, but it had nothing to do with inheritance. It’s more “nine ways to do polymorphism-adjacent things using ad-hoc polymorphism (“traits”) instead of subtype polymorphism (‘inheritance’)”

show 2 replies
zozbot234today at 6:35 AM

Much of this post seems to focus on interface inheritance via traits, which is a well-known feature of Rust. It's weird though that it completely misses the generic typestate pattern, which is pretty unique to Rust as far as it goes and can be quite fairly described as OOP implementation inheritance in a type-theoretic trench coat.

jmclnxtoday at 12:43 PM

I know little about rust, but not having inheritance to me is a big benefit :)