It's posible it all just means I need to refactor. Ideally I'd like to create a separate Clickable trait, but I'm not sure how to check for a trait at runtime. I'd like all of the children to be Widgets but only some to be Clickable, and somehow be able to traverse the tree and use either where appropriate, but haven't figured out what that looks like. Is there a way to "detect" another trait implementation after a trait object has been created? My gut says no, that contradicts what I know about trait objects.
Yeah, I came across that too and played with it a little, but never found anything that didn't feel similarly kludgy. I don't really want to forfeit type checking, seems like a deeper structural change is likely in order.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
It's posible it all just means I need to refactor. Ideally I'd like to create a separate
Clickable
trait, but I'm not sure how to check for a trait at runtime. I'd like all of the children to beWidget
s but only some to beClickable
, and somehow be able to traverse the tree and use either where appropriate, but haven't figured out what that looks like. Is there a way to "detect" another trait implementation after a trait object has been created? My gut says no, that contradicts what I know about trait objects.Just realized I've yet looked at how to do that. Seems std::any::Any is the current solution.
But you're right, I suspect there's more Rust-y way to implement things.
Yeah, I came across that too and played with it a little, but never found anything that didn't feel similarly kludgy. I don't really want to forfeit type checking, seems like a deeper structural change is likely in order.