on-internet
← Community

How to downcast any List or any Option in rust

Stack Overflow ·

I want to add properties window with auto properties based on struct fields. I'am downcasting every field, but for Vec<> and Option<> I have to duplicate all code, how can I automatically check is that any Option or Vec. Downcaster: pub fn downcast_property(ui: &mut Ui, title: &str, value_mut: &mut (dyn Any + 'static), interactable: bool) { if let Some(string_v) = value_mut.downcast_mut::<String>() { string_property(ui, title, string_v, interactable); } else if let Some(int_v) = value_mut.downcast_mut::<i32>() { i_property(ui, title, int_v, interactable); } else if let Some(float_v) = value_mu

Comments

Sign in or sign up to comment and upvote.

No comments yet.