Just found some Rust code from a couple of years ago where I used Deref and DerefMut to essentially simulate inheritance...oops 
-
-
It fails the Liskov substitution principle: Deref cocercion means the “subclass” inherits/impls none of the traits of the parent “class”. But it can work in a pinch
-
Are we judging things on abstract principles of questionable value?
End of conversation
New conversation -
-
-
the reason it's an antipattern is that it doesn't work: Deref isn't designed for this purpose and it breaks down. It doesn't always coerce, and it doesn't work with traits. String and vec are smart pointers, they're smart pointers to DSTs.
-
I work on a codebase that *has* to have inheritance because Javascript and we don't use deref because it just wouldn't work. Transitive dereffability isn't something you can deal with with traits (but you can with Servo's Castable). Autoderef doesn't give you trait bounds. etc.
- 4 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.