#Is there a way to access the currently set `DynamicVariant` of a `DynamicEnum`?
21 messages · Page 1 of 1 (latest)
you can set via index, and there's some way to get the index from the name
i don't want to set it, i want to inspect it and modify it in place
let mut dynamic_enum = get_a_dynamic_enum_from_somewhere();
let variant = dynamic_enum.variant_mut(); // this function is not real
match variant {
DynamicVariant::Struct(dynamic_struct) => todo!(),
_ => ()
}
then i modify fields of the struct
it needs to be in place because it already has data in it that i don't want to lose
my use case is that i use pyo3 to convert between python objects and bevy reflect
<DynamicEnum as Enum>::field_at_mut?
yes, that's what i was looking for, thank you so much!
wait, hold on
that gets a Option<&dyn PartialReflect>, it returns the value of a field in the current variant
it doesn't say which variant, and it returns None if the the current variant is not a tuple
there's also variant_name, variant_index, and variant_type
tuple or non-tuple struct
non-tuple structs are given indices too
returns None iff index >= length iirc