PokeEnum

Struct PokeEnum 

Source
pub struct PokeEnum<'mem, 'facet> { /* private fields */ }
Expand description

Lets you mutate an enum’s fields.

Implementations§

Source§

impl<'mem, 'facet> PokeEnum<'mem, 'facet>

Source

pub fn ty(&self) -> EnumType

Returns the enum definition

Source

pub fn enum_repr(&self) -> EnumRepr

Returns the enum representation

Source

pub fn variants(&self) -> &'static [Variant]

Returns the enum variants

Source

pub fn variant_count(&self) -> usize

Returns the number of variants in this enum

Source

pub fn variant_name(&self, index: usize) -> Option<&'static str>

Returns the variant name at the given index

Source

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.

Source

pub fn variant_index(&self) -> Result<usize, VariantError>

Returns the variant index for this enum value

Source

pub fn active_variant(&self) -> Result<&'static Variant, VariantError>

Returns the active variant

Source

pub fn variant_name_active(&self) -> Result<&'static str, VariantError>

Returns the name of the active variant for this enum value

Source

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

Source

pub fn field_index( &self, field_name: &str, ) -> Result<Option<usize>, VariantError>

Returns the index of a field in the active variant by name

Source

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

Source

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
Source

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
Source

pub fn peek_field( &self, index: usize, ) -> Result<Option<Peek<'_, 'facet>>, VariantError>

Gets a read-only view of a field by index.

Source

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.

Source

pub fn into_inner(self) -> Poke<'mem, 'facet>

Converts this back into the underlying Poke.

Source

pub fn as_peek_enum(&self) -> PeekEnum<'_, 'facet>

Returns a read-only PeekEnum view.

Trait Implementations§

Source§

impl Debug for PokeEnum<'_, '_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'mem, 'facet> Freeze for PokeEnum<'mem, 'facet>

§

impl<'mem, 'facet> RefUnwindSafe for PokeEnum<'mem, 'facet>

§

impl<'mem, 'facet> !Send for PokeEnum<'mem, 'facet>

§

impl<'mem, 'facet> !Sync for PokeEnum<'mem, 'facet>

§

impl<'mem, 'facet> Unpin for PokeEnum<'mem, 'facet>

§

impl<'mem, 'facet> !UnwindSafe for PokeEnum<'mem, 'facet>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.