Can't use traits for one-level hierarchy
⚓ Rust 📅 2025-09-28 👤 surdeus 👁️ 6I've a simple, closed-set of implementors, like:
- DisplayObject— trait- Container— struct
- MovieClip— struct
- Image— struct
- More
 
The goal is to have 2D hierarchical nodes which implement rendering and share a lot of common properties (through a common() required method, used for other optional methods).
I had, however, given up in using this hierarchy because I got some Rc specific up/downcasting issues. I think I specifically run into some limitation with Rc<dyn DisplayObject>. Perhaps I was about to use a generic and forgot the ?Sized constraint, but not sure...
So I'm actually almost about to settle down with composition using a struct and an enum, but I honestly preferred traits except when it comes to PartialEq and Hash applied to DisplayObject references.
3 posts - 2 participants
🏷️ Rust_feed