logoalt Hacker News

zozbot234last Wednesday at 8:13 AM0 repliesview on HN

It's worth noting that you can replicate implementation inheritance pretty much as-is in Rust by using the generic typestate pattern. This is effectively what OP calls "policies" except that the policies can also bundle data of their own, just like our derived classes of old; they aren't just limited to picking some statically-known behavior at compile time.

The key difference compared to OOP inheritance is simply that generic typestate is explicitly anti-modular: your "base" and "derived" slices are expressly contained within a single program module. You still have extensibility - you can create new "derived" slices to go with some existing "base" - but now there is no attempt to use implementation inheritance as a "programming in the large" strategy or pattern; that is done by using more robust modularity mechanisms.