Struct PokeStruct

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

Allows poking a struct (setting fields, etc.)

Implementations§

Source§

impl<'mem> PokeStruct<'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 unsafe fn new( data: OpaqueUninit<'mem>, shape: &'static Shape, def: StructDef, ) -> Self

Creates a new PokeStruct

§Safety

The data, shape, and def must match

Source

pub fn assert_all_fields_initialized(&self)

Checks if all fields in the struct have been initialized. Panics if any field is not initialized, providing details about the uninitialized field.

Source

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

Asserts that every field has been initialized and forgets the PokeStruct.

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

§Panics

This function will panic if any field is not initialized.

Source

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

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

§Panics

This function will panic if:

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

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

Build that PokeStruct into a boxed completed shape.

§Panics

This function will panic if:

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

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

Moves the contents of this PokeStruct 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.

Source

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

Gets a field, by name

Source

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

Get a field writer for a field by index.

§Errors

Returns an error if:

  • The shape doesn’t represent a struct.
  • The index is out of bounds.
Source

pub unsafe fn unchecked_set( &mut self, index: usize, value: OpaqueConst<'_>, ) -> Result<(), FieldError>

Sets a field’s value by its index, directly copying raw memory.

§Safety

This is unsafe because it directly copies memory without checking types. The caller must ensure that value is of the correct type for the field.

§Errors

Returns an error if:

  • The index is out of bounds
  • The field shapes don’t match
Source

pub unsafe fn unchecked_set_by_name( &mut self, name: &str, value: OpaqueConst<'_>, ) -> Result<(), FieldError>

Sets a field’s value by its name, directly copying raw memory.

§Safety

This is unsafe because it directly copies memory without checking types. The caller must ensure that value is of the correct type for the field.

§Errors

Returns an error if:

  • The field name doesn’t exist
  • The field shapes don’t match
Source

pub fn set<T: Facet>( &mut self, index: usize, value: T, ) -> Result<(), FieldError>

Sets a field’s value by its index in a type-safe manner.

This method takes ownership of the value and ensures proper memory management.

§Errors

Returns an error if:

  • The index is out of bounds
  • The field shapes don’t match
Source

pub fn set_by_name<T: Facet>( &mut self, name: &str, value: T, ) -> Result<(), FieldError>

Sets a field’s value by its name in a type-safe manner.

This method takes ownership of the value and ensures proper memory management.

§Errors

Returns an error if:

  • The field name doesn’t exist
  • The field shapes don’t match
Source

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

Marks a field as initialized.

§Safety

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

Source

pub fn def(&self) -> StructDef

Gets the struct definition

Trait Implementations§

Source§

impl Drop for PokeStruct<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'mem> Freeze for PokeStruct<'mem>

§

impl<'mem> RefUnwindSafe for PokeStruct<'mem>

§

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

§

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

§

impl<'mem> Unpin for PokeStruct<'mem>

§

impl<'mem> !UnwindSafe for PokeStruct<'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.