pub struct PokeStruct<'mem> { /* private fields */ }Expand description
Allows poking a struct (setting fields, etc.)
Implementations§
Source§impl<'mem> PokeStruct<'mem>
impl<'mem> PokeStruct<'mem>
Sourcepub fn into_value(self) -> PokeValueUninit<'mem>
pub fn into_value(self) -> PokeValueUninit<'mem>
Coerce back into a PokeValue
Sourcepub unsafe fn new(
data: OpaqueUninit<'mem>,
shape: &'static Shape,
def: StructDef,
) -> Self
pub unsafe fn new( data: OpaqueUninit<'mem>, shape: &'static Shape, def: StructDef, ) -> Self
Sourcepub fn assert_all_fields_initialized(&self)
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.
Sourcepub fn build_in_place(self) -> Opaque<'mem>
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.
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 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.
Sourcepub fn build_boxed<T: Facet>(self) -> Box<T>
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.
Sourcepub unsafe fn move_into(self, target: NonNull<u8>, guard: Option<Guard>)
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.
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
Sourcepub fn field(&self, index: usize) -> Result<PokeUninit<'mem>, FieldError>
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.
Sourcepub unsafe fn unchecked_set(
&mut self,
index: usize,
value: OpaqueConst<'_>,
) -> Result<(), FieldError>
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
Sourcepub unsafe fn unchecked_set_by_name(
&mut self,
name: &str,
value: OpaqueConst<'_>,
) -> Result<(), FieldError>
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
Sourcepub fn set<T: Facet>(
&mut self,
index: usize,
value: T,
) -> Result<(), FieldError>
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
Sourcepub fn set_by_name<T: Facet>(
&mut self,
name: &str,
value: T,
) -> Result<(), FieldError>
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
Sourcepub unsafe fn mark_initialized(&mut self, index: usize)
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.