News for hackers. Stuff that matters.
Re:Bayard: a full-text search and indexing server written in... by heavenlyblue on Friday November 01, 2019 @12:21PM (#21420517)
Rust has inheritance and polymorphism.
Re:Bayard: a full-text search and indexing server written in... by vertex-four on Friday November 01, 2019 @12:25PM (#21420586)
Rust has trait inheritance, but not object inheritance. Servo uses code generation and macros to get around this. (I’m literally writing an operating system in Rust, I know what I’m talking about.)
Re:Bayard: a full-text search and indexing server written in... by heavenlyblue on Friday November 01, 2019 @04:41PM (#21423477)
Could you elaborate on how trait inheritance is different from object inheritance?
Re:Bayard: a full-text search and indexing server written in... by zozbot234 on Friday November 01, 2019 @09:01PM (#21425197)
"Trait" inheritance is just interface inheritance, which is indistinguishable from composition+delegation. It doesn't have the pitfalls of actual implementation inheritance, which essentially involves an extra "trick" of dispatching on the actual type of your object even when calling base-class methods. It's not that Rust cannot do this - heck, people do it all the time in C. But it has to be done by writing things out explicitly, it's not automatic in any sense. And for good reason - letting base-class code access methods that have been redefined in a derived class can create all sorts of pitfalls when you're not very careful about what that implies.