Skip to main content

PokeDynamicValue

Struct PokeDynamicValue 

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

Lets you mutate a dynamic value (implements mutable operations for DynamicValue types).

This is used for types like facet_value::Value that can hold any of: null, bool, number, string, bytes, array, or object - determined at runtime.

The setter methods (set_null, set_bool, etc.) drop the previous value and re-initialize the storage with the new kind.

Implementations§

Source§

impl<'mem, 'facet> PokeDynamicValue<'mem, 'facet>

Source

pub const unsafe fn new(value: Poke<'mem, 'facet>, def: DynamicValueDef) -> Self

Creates a new poke dynamic value.

§Safety

The caller must ensure that def contains valid vtable function pointers that correctly implement the dynamic-value operations for the actual type.

Source

pub const fn def(&self) -> DynamicValueDef

Returns the dynamic value definition.

Source

pub fn as_peek(&self) -> Peek<'_, 'facet>

Returns the underlying Poke as a read-only Peek.

Source

pub fn kind(&self) -> DynValueKind

Returns the kind of value stored.

Source

pub fn is_null(&self) -> bool

Returns true if the value is null.

Source

pub fn as_bool(&self) -> Option<bool>

Returns the boolean value if this is a bool, None otherwise.

Source

pub fn as_i64(&self) -> Option<i64>

Returns the i64 value if representable, None otherwise.

Source

pub fn as_u64(&self) -> Option<u64>

Returns the u64 value if representable, None otherwise.

Source

pub fn as_f64(&self) -> Option<f64>

Returns the f64 value if this is a number, None otherwise.

Source

pub fn as_str(&self) -> Option<&str>

Returns the string value if this is a string, None otherwise.

Source

pub fn as_bytes(&self) -> Option<&[u8]>

Returns the bytes value if this is bytes, None otherwise.

Source

pub fn array_len(&self) -> Option<usize>

Returns the length of the array if this is an array, None otherwise.

Source

pub fn object_len(&self) -> Option<usize>

Returns the length of the object if this is an object, None otherwise.

Source

pub fn set_null(&mut self)

Replace the value with null, dropping the previous contents.

Source

pub fn set_bool(&mut self, v: bool)

Replace the value with a boolean, dropping the previous contents.

Source

pub fn set_i64(&mut self, v: i64)

Replace the value with an i64, dropping the previous contents.

Source

pub fn set_u64(&mut self, v: u64)

Replace the value with a u64, dropping the previous contents.

Source

pub fn set_f64(&mut self, v: f64) -> bool

Replace the value with an f64, dropping the previous contents.

Returns false if the value is not representable by the underlying type.

Source

pub fn set_str(&mut self, v: &str)

Replace the value with a string, dropping the previous contents.

Source

pub fn set_bytes(&mut self, v: &[u8]) -> bool

Replace the value with a byte slice, dropping the previous contents.

Returns false if the underlying dynamic value type doesn’t support bytes.

Source

pub fn set_array(&mut self)

Replace the value with an empty array, dropping the previous contents.

Source

pub fn set_object(&mut self)

Replace the value with an empty object, dropping the previous contents.

Source

pub fn push_array_element<T: Facet<'facet>>( &mut self, element: T, ) -> Result<(), ReflectError>

Push an element onto the array value.

The value must already be an array (use set_array first if needed). The element’s shape must match this dynamic value’s shape — a nested element is itself a full dynamic value of the same kind (e.g. another facet_value::Value).

The element is moved into the array (the vtable does the ptr::read); the caller’s original ownership of element is consumed by this call.

Source

pub fn push_array_element_from_heap<const BORROW: bool>( &mut self, element: HeapValue<'facet, BORROW>, ) -> Result<(), ReflectError>

Type-erased push_array_element.

Accepts a HeapValue whose shape must match this dynamic value’s shape.

Source

pub fn end_array(&mut self)

Finalize an array value. No-op if the underlying dynamic-value type doesn’t need it.

Source

pub fn insert_object_entry<T: Facet<'facet>>( &mut self, key: &str, value: T, ) -> Result<(), ReflectError>

Insert a key-value pair into the object value.

The value must already be an object (use set_object first if needed). The value’s shape must match this dynamic value’s shape — a nested value is itself a full dynamic value of the same kind.

value is moved into the object (the vtable does the ptr::read).

Source

pub fn insert_object_entry_from_heap<const BORROW: bool>( &mut self, key: &str, value: HeapValue<'facet, BORROW>, ) -> Result<(), ReflectError>

Type-erased insert_object_entry.

Accepts a HeapValue whose shape must match this dynamic value’s shape.

Source

pub fn end_object(&mut self)

Finalize an object value. No-op if the underlying dynamic-value type doesn’t need it.

Source

pub fn object_get_mut(&mut self, key: &str) -> Option<Poke<'_, 'facet>>

Get a mutable Poke for the value at the given object key.

Returns None if the dynamic value is not an object, the key is missing, or object_get_mut is not implemented for this type.

Source

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

Converts this PokeDynamicValue back into a Poke.

Source

pub fn as_peek_dynamic_value(&self) -> PeekDynamicValue<'_, 'facet>

Returns a read-only PeekDynamicValue view.

Trait Implementations§

Source§

impl<'mem, 'facet> Debug for PokeDynamicValue<'mem, 'facet>

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 PokeDynamicValue<'mem, 'facet>

§

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

§

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

§

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

§

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

§

impl<'mem, 'facet> UnsafeUnpin for PokeDynamicValue<'mem, 'facet>

§

impl<'mem, 'facet> !UnwindSafe for PokeDynamicValue<'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.