pub struct PokeEnum<'mem, 'facet> { /* private fields */ }Expand description
Lets you mutate an enum’s fields.
Implementations§
Source§impl<'mem, 'facet> PokeEnum<'mem, 'facet>
impl<'mem, 'facet> PokeEnum<'mem, 'facet>
Sourcepub fn variant_count(&self) -> usize
pub fn variant_count(&self) -> usize
Returns the number of variants in this enum
Sourcepub fn variant_name(&self, index: usize) -> Option<&'static str>
pub fn variant_name(&self, index: usize) -> Option<&'static str>
Returns the variant name at the given index
Sourcepub fn discriminant(&self) -> i64
pub fn discriminant(&self) -> i64
Returns the discriminant value for the current enum value
Note: For RustNPO (null pointer optimization) types, there is no explicit
discriminant stored in memory. In this case, 0 is returned. Use
variant_index() to determine the active variant for NPO types.
Sourcepub fn variant_index(&self) -> Result<usize, VariantError>
pub fn variant_index(&self) -> Result<usize, VariantError>
Returns the variant index for this enum value
Sourcepub fn active_variant(&self) -> Result<&'static Variant, VariantError>
pub fn active_variant(&self) -> Result<&'static Variant, VariantError>
Returns the active variant
Sourcepub fn variant_name_active(&self) -> Result<&'static str, VariantError>
pub fn variant_name_active(&self) -> Result<&'static str, VariantError>
Returns the name of the active variant for this enum value
Sourcepub fn field(
&mut self,
index: usize,
) -> Result<Option<Poke<'_, 'facet>>, VariantError>
pub fn field( &mut self, index: usize, ) -> Result<Option<Poke<'_, 'facet>>, VariantError>
Returns a Poke handle to a field of a tuple or struct variant by index
Sourcepub fn field_index(
&self,
field_name: &str,
) -> Result<Option<usize>, VariantError>
pub fn field_index( &self, field_name: &str, ) -> Result<Option<usize>, VariantError>
Returns the index of a field in the active variant by name
Sourcepub fn field_by_name(
&mut self,
field_name: &str,
) -> Result<Option<Poke<'_, 'facet>>, VariantError>
pub fn field_by_name( &mut self, field_name: &str, ) -> Result<Option<Poke<'_, 'facet>>, VariantError>
Returns a Poke handle to a field of a tuple or struct variant by name
Sourcepub fn set_field<T: Facet<'facet>>(
&mut self,
index: usize,
value: T,
) -> Result<(), ReflectError>
pub fn set_field<T: Facet<'facet>>( &mut self, index: usize, value: T, ) -> Result<(), ReflectError>
Sets a field of the current variant by index.
Returns an error if:
- The parent enum is not POD
- The index is out of bounds
- The value type doesn’t match the field type
Sourcepub fn set_field_by_name<T: Facet<'facet>>(
&mut self,
name: &str,
value: T,
) -> Result<(), ReflectError>
pub fn set_field_by_name<T: Facet<'facet>>( &mut self, name: &str, value: T, ) -> Result<(), ReflectError>
Sets a field of the current variant by name.
Returns an error if:
- The parent enum is not POD
- No field with the given name exists
- The value type doesn’t match the field type
Sourcepub fn peek_field(
&self,
index: usize,
) -> Result<Option<Peek<'_, 'facet>>, VariantError>
pub fn peek_field( &self, index: usize, ) -> Result<Option<Peek<'_, 'facet>>, VariantError>
Gets a read-only view of a field by index.
Sourcepub fn peek_field_by_name(
&self,
field_name: &str,
) -> Result<Option<Peek<'_, 'facet>>, VariantError>
pub fn peek_field_by_name( &self, field_name: &str, ) -> Result<Option<Peek<'_, 'facet>>, VariantError>
Gets a read-only view of a field by name.
Sourcepub fn into_inner(self) -> Poke<'mem, 'facet>
pub fn into_inner(self) -> Poke<'mem, 'facet>
Converts this back into the underlying Poke.
Sourcepub fn as_peek_enum(&self) -> PeekEnum<'_, 'facet>
pub fn as_peek_enum(&self) -> PeekEnum<'_, 'facet>
Returns a read-only PeekEnum view.