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>
impl<'mem> PokeEnum<'mem>
Sourcepub fn into_value(self) -> PokeValueUninit<'mem>
pub fn into_value(self) -> PokeValueUninit<'mem>
Coerce back into a PokeValue
Sourcepub fn selected_variant_index(&self) -> usize
pub fn selected_variant_index(&self) -> usize
Returns the currently selected variant index
Sourcepub fn field_by_name(
&self,
name: &str,
) -> Result<(usize, PokeUninit<'mem>), FieldError>
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).
Sourcepub fn tuple_field(&self, index: usize) -> Result<PokeUninit<'mem>, FieldError>
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.
Sourcepub unsafe fn mark_initialized(&mut self, field_index: usize)
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.
Sourcepub fn assert_all_fields_initialized(&self)
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.
Sourcepub fn build_in_place(self) -> Opaque<'mem>
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.
Sourcepub fn build<T: Facet>(self, guard: Option<Guard>) -> T
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.
Sourcepub fn build_boxed<T: Facet>(self) -> Box<T>
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.
Sourcepub unsafe fn move_into(self, target: NonNull<u8>)
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.