PokeStruct

Struct PokeStruct 

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

Lets you mutate a struct’s fields.

Implementations§

Source§

impl<'mem, 'facet> PokeStruct<'mem, 'facet>

Source

pub fn ty(&self) -> &StructType

Returns the struct definition.

Source

pub fn field_count(&self) -> usize

Returns the number of fields in this struct.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn peek_field(&self, index: usize) -> Result<Peek<'_, 'facet>, FieldError>

Gets a read-only view of a field by index.

Source

pub fn peek_field_by_name( &self, name: &str, ) -> Result<Peek<'_, 'facet>, FieldError>

Gets a read-only view of a field by name.

Source

pub fn into_inner(self) -> Poke<'mem, 'facet>

Converts this back into the underlying Poke.

Source

pub fn as_peek_struct(&self) -> PeekStruct<'_, 'facet>

Returns a read-only PeekStruct view.

Trait Implementations§

Source§

impl Debug for PokeStruct<'_, '_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<'mem, 'facet> !UnwindSafe for PokeStruct<'mem, 'facet>

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.