3 ms·
> The preferred solution to having multiple types of nodes in the same tree is to use an enum That's not really a great option for a widget library, because it
by mercurial 10y ago
> The preferred solution to having multiple types of nodes in the same tree is to use an enum
That's not really a great option for a widget library, because it means no custom widgets.
- ekidd 10y agoIn that case, just use Vec<Box<Widget>>, which means "a vector of objects which implement the Widget interface."
- deleted 10y ago[deleted]
- derkha 10y agoBut widgets do have the same type: Widget, which the author already uses as a trait object. I think he was getting confused by mixing &Widget and Rc<RefCell<Widget>>. Just declare a type alias for the latter, use it everywhere, and it should work. You would do the about the same thing in C++, I believe.
- pcwalton 10y agoYes, it does. You can use a trait to provide extensibility.