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>
impl<'mem, 'facet> PokeDynamicValue<'mem, 'facet>
Sourcepub const unsafe fn new(value: Poke<'mem, 'facet>, def: DynamicValueDef) -> Self
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.
Sourcepub const fn def(&self) -> DynamicValueDef
pub const fn def(&self) -> DynamicValueDef
Returns the dynamic value definition.
Sourcepub fn kind(&self) -> DynValueKind
pub fn kind(&self) -> DynValueKind
Returns the kind of value stored.
Sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
Returns the boolean value if this is a bool, None otherwise.
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Returns the string value if this is a string, None otherwise.
Sourcepub fn as_bytes(&self) -> Option<&[u8]>
pub fn as_bytes(&self) -> Option<&[u8]>
Returns the bytes value if this is bytes, None otherwise.
Sourcepub fn array_len(&self) -> Option<usize>
pub fn array_len(&self) -> Option<usize>
Returns the length of the array if this is an array, None otherwise.
Sourcepub fn object_len(&self) -> Option<usize>
pub fn object_len(&self) -> Option<usize>
Returns the length of the object if this is an object, None otherwise.
Sourcepub fn set_bool(&mut self, v: bool)
pub fn set_bool(&mut self, v: bool)
Replace the value with a boolean, dropping the previous contents.
Sourcepub fn set_i64(&mut self, v: i64)
pub fn set_i64(&mut self, v: i64)
Replace the value with an i64, dropping the previous contents.
Sourcepub fn set_u64(&mut self, v: u64)
pub fn set_u64(&mut self, v: u64)
Replace the value with a u64, dropping the previous contents.
Sourcepub fn set_f64(&mut self, v: f64) -> bool
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.
Sourcepub fn set_str(&mut self, v: &str)
pub fn set_str(&mut self, v: &str)
Replace the value with a string, dropping the previous contents.
Sourcepub fn set_bytes(&mut self, v: &[u8]) -> bool
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.
Sourcepub fn set_array(&mut self)
pub fn set_array(&mut self)
Replace the value with an empty array, dropping the previous contents.
Sourcepub fn set_object(&mut self)
pub fn set_object(&mut self)
Replace the value with an empty object, dropping the previous contents.
Sourcepub fn push_array_element<T: Facet<'facet>>(
&mut self,
element: T,
) -> Result<(), ReflectError>
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.
Sourcepub fn push_array_element_from_heap<const BORROW: bool>(
&mut self,
element: HeapValue<'facet, BORROW>,
) -> Result<(), ReflectError>
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.
Sourcepub fn end_array(&mut self)
pub fn end_array(&mut self)
Finalize an array value. No-op if the underlying dynamic-value type doesn’t need it.
Sourcepub fn insert_object_entry<T: Facet<'facet>>(
&mut self,
key: &str,
value: T,
) -> Result<(), ReflectError>
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).
Sourcepub fn insert_object_entry_from_heap<const BORROW: bool>(
&mut self,
key: &str,
value: HeapValue<'facet, BORROW>,
) -> Result<(), ReflectError>
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.
Sourcepub fn end_object(&mut self)
pub fn end_object(&mut self)
Finalize an object value. No-op if the underlying dynamic-value type doesn’t need it.
Sourcepub fn object_get_mut(&mut self, key: &str) -> Option<Poke<'_, 'facet>>
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.
Sourcepub const fn into_inner(self) -> Poke<'mem, 'facet>
pub const fn into_inner(self) -> Poke<'mem, 'facet>
Converts this PokeDynamicValue back into a Poke.
Sourcepub fn as_peek_dynamic_value(&self) -> PeekDynamicValue<'_, 'facet>
pub fn as_peek_dynamic_value(&self) -> PeekDynamicValue<'_, 'facet>
Returns a read-only PeekDynamicValue view.