pub struct PokeStruct<'mem, 'facet> { /* private fields */ }Expand description
Lets you mutate a struct’s fields.
Implementations§
Source§impl<'mem, 'facet> PokeStruct<'mem, 'facet>
impl<'mem, 'facet> PokeStruct<'mem, 'facet>
Sourcepub fn ty(&self) -> &StructType
pub fn ty(&self) -> &StructType
Returns the struct definition.
Sourcepub fn field_count(&self) -> usize
pub fn field_count(&self) -> usize
Returns the number of fields in this struct.
Sourcepub fn field(&mut self, index: usize) -> Result<Poke<'_, 'facet>, ReflectError>
pub fn field(&mut self, index: usize) -> Result<Poke<'_, 'facet>, ReflectError>
Returns a Poke for the field at the given index.
This always succeeds (for valid indices). The POD check happens when
you try to mutate via Poke::set on the returned field poke, or
when calling PokeStruct::set_field which checks the parent struct.
Sourcepub fn field_by_name(
&mut self,
name: &str,
) -> Result<Poke<'_, 'facet>, ReflectError>
pub fn field_by_name( &mut self, name: &str, ) -> Result<Poke<'_, 'facet>, ReflectError>
Returns a Poke for the field with the given name.
Returns an error if the field is not found.
Sourcepub fn set_field<T: Facet<'facet>>(
&mut self,
index: usize,
value: T,
) -> Result<(), ReflectError>
pub fn set_field<T: Facet<'facet>>( &mut self, index: usize, value: T, ) -> Result<(), ReflectError>
Sets the value of a field by index.
The value type must match the field’s type.
Returns an error if the parent struct is not POD. Field mutation could
violate struct-level invariants, so the struct must be marked with
#[facet(pod)] to allow this.
Sourcepub fn set_field_by_name<T: Facet<'facet>>(
&mut self,
name: &str,
value: T,
) -> Result<(), ReflectError>
pub fn set_field_by_name<T: Facet<'facet>>( &mut self, name: &str, value: T, ) -> Result<(), ReflectError>
Sets the value of a field by name.
The value type must match the field’s type.
Sourcepub fn peek_field(&self, index: usize) -> Result<Peek<'_, 'facet>, FieldError>
pub fn peek_field(&self, index: usize) -> Result<Peek<'_, 'facet>, FieldError>
Gets a read-only view of a field by index.
Sourcepub fn peek_field_by_name(
&self,
name: &str,
) -> Result<Peek<'_, 'facet>, FieldError>
pub fn peek_field_by_name( &self, name: &str, ) -> Result<Peek<'_, 'facet>, FieldError>
Gets a read-only view of a field by name.
Sourcepub fn into_inner(self) -> Poke<'mem, 'facet>
pub fn into_inner(self) -> Poke<'mem, 'facet>
Converts this back into the underlying Poke.
Sourcepub fn as_peek_struct(&self) -> PeekStruct<'_, 'facet>
pub fn as_peek_struct(&self) -> PeekStruct<'_, 'facet>
Returns a read-only PeekStruct view.