Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You probably know this, but for reference, while Rust doesn’t support implementation inheritance, it has inheritance and runtime polymorphism at the interface level.

You put your dynamic components into references and smart pointers of the form Box<dyn Component>, where Component is a so-called “object-safe trait” (which is exactly what you’d call an interface in the OO world). These traits can inherit from each other, and you can upcast a Box<ConcreteType> into a Box<dyn Interface> into a Box<dyn ParentInterface>.



No I don't know Rust very well, I really should put in some time to learn it properly! I did a bit of GUI programming in the past, and felt there is a bit of impedance mismatch with Rust there. And the kind of subtle mistakes with ownership and reference cycles you tend to make in C++, but discover when you move to unique_ptr: Rust also ruthlessly uncovers them, but I guess I need more experience how to solve them.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: