Skip to content

Commit 989b360

Browse files
authored
Add accessors to DynamicEnum for the DynamicVariant (#18693)
# Objective - Closes #18692 ## Solution Add the methods as described ```rust impl DynamicEnum { fn variant(&self) -> &DynamicVariant; fn variant_mut(&mut self) -> &mut DynamicVariant; } ```
1 parent 5da64dd commit 989b360

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

crates/bevy_reflect/src/enums/dynamic_enum.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,22 @@ impl DynamicEnum {
140140
self.variant = variant.into();
141141
}
142142

143+
/// Get a reference to the [`DynamicVariant`] contained in `self`.
144+
pub fn variant(&self) -> &DynamicVariant {
145+
&self.variant
146+
}
147+
148+
/// Get a mutable reference to the [`DynamicVariant`] contained in `self`.
149+
///
150+
/// Using the mut reference to switch to a different variant will ___not___ update the
151+
/// internal tracking of the variant name and index.
152+
///
153+
/// If you want to switch variants, prefer one of the setters:
154+
/// [`DynamicEnum::set_variant`] or [`DynamicEnum::set_variant_with_index`].
155+
pub fn variant_mut(&mut self) -> &mut DynamicVariant {
156+
&mut self.variant
157+
}
158+
143159
/// Create a [`DynamicEnum`] from an existing one.
144160
///
145161
/// This is functionally the same as [`DynamicEnum::from_ref`] except it takes an owned value.

0 commit comments

Comments
 (0)