Struct PokeEnum

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

Allows poking an enum with a selected variant (setting fields, etc.)

Implementations§

Source§

impl<'mem> PokeEnum<'mem>

Source

pub fn into_value(self) -> PokeValueUninit<'mem>

Coerce back into a PokeValue

Source

pub fn shape(&self) -> &'static Shape

Shape getter

Source

pub fn selected_variant_index(&self) -> usize

Returns the currently selected variant index

Source

pub fn field_by_name( &self, name: &str, ) -> Result<(usize, PokeUninit<'mem>), FieldError>

Gets a field by name in the currently selected variant.

§Errors

Returns an error if:

  • The field name doesn’t exist in the selected variant.
  • The selected variant is a unit variant (which has no fields).
Source

pub fn tuple_field(&self, index: usize) -> Result<PokeUninit<'mem>, FieldError>

Get a field writer for a tuple field by index in the currently selected variant.

§Errors

Returns an error if:

  • The index is out of bounds.
  • The selected variant is not a tuple variant.
Source

pub unsafe fn mark_initialized(&mut self, field_index: usize)

Marks a field in the current variant as initialized.

§Safety

The caller must ensure that the field is initialized. Only call this after writing to an address gotten through Self::field_by_name or Self::tuple_field.

Source

pub fn assert_all_fields_initialized(&self)

Checks if all required fields in the enum are initialized.

§Panics

Panics if any field in the selected variant is not initialized.

Source

pub fn build_in_place(self) -> Opaque<'mem>

Asserts that every field in the selected variant has been initialized and forgets the PokeEnum.

This method is only used when the origin is borrowed. If this method is not called, all fields will be freed when the PokeEnum is dropped.

§Panics

This function will panic if any required field is not initialized.

Source

pub fn build<T: Facet>(self, guard: Option<Guard>) -> T

Builds a value of type T from the PokeEnum, then deallocates the memory that this PokeEnum was pointing to.

§Panics

This function will panic if:

  • Not all fields in the selected variant have been initialized.
  • The generic type parameter T does not match the shape that this PokeEnum is building.
Source

pub fn build_boxed<T: Facet>(self) -> Box<T>

Build that PokeEnum into a boxed completed shape.

§Panics

This function will panic if:

  • Not all fields in the selected variant have been initialized.
  • The generic type parameter T does not match the shape that this PokeEnum is building.
Source

pub unsafe fn move_into(self, target: NonNull<u8>)

Moves the contents of this PokeEnum into a target memory location.

§Safety

The target pointer must be valid and properly aligned, and must be large enough to hold the value. The caller is responsible for ensuring that the target memory is properly deallocated when it’s no longer needed.

Trait Implementations§

Source§

impl Drop for PokeEnum<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

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.