pub struct Value { /* private fields */ }Expand description
A dynamic value that can represent null, booleans, numbers, strings, bytes, arrays, or objects.
Value is exactly one pointer in size and uses tagged pointers for efficient type discrimination.
Small values like null, booleans, and small integers are stored inline without heap allocation.
Implementations§
Source§impl Value
impl Value
Sourcepub fn value_type(&self) -> ValueType
pub fn value_type(&self) -> ValueType
Returns the type of this value.
Sourcepub fn is_datetime(&self) -> bool
pub fn is_datetime(&self) -> bool
Returns true if this is a datetime.
Sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
Converts this value to a bool. Returns None if not a boolean.
Sourcepub fn as_number(&self) -> Option<&VNumber>
pub fn as_number(&self) -> Option<&VNumber>
Gets a reference to this value as a VNumber. Returns None if not a number.
Sourcepub fn as_number_mut(&mut self) -> Option<&mut VNumber>
pub fn as_number_mut(&mut self) -> Option<&mut VNumber>
Gets a mutable reference to this value as a VNumber.
Sourcepub fn as_string(&self) -> Option<&VString>
pub fn as_string(&self) -> Option<&VString>
Gets a reference to this value as a VString. Returns None if not a string.
Sourcepub fn as_string_mut(&mut self) -> Option<&mut VString>
pub fn as_string_mut(&mut self) -> Option<&mut VString>
Gets a mutable reference to this value as a VString.
Sourcepub fn is_safe_string(&self) -> bool
pub fn is_safe_string(&self) -> bool
Returns true if this is a safe string (marked as pre-escaped HTML, etc.).
A safe string is a string with the safe flag set. Inline strings are never safe.
Sourcepub fn as_safe_string(&self) -> Option<&VSafeString>
pub fn as_safe_string(&self) -> Option<&VSafeString>
Gets a reference to this value as a VSafeString. Returns None if not a safe string.
Sourcepub fn as_safe_string_mut(&mut self) -> Option<&mut VSafeString>
pub fn as_safe_string_mut(&mut self) -> Option<&mut VSafeString>
Gets a mutable reference to this value as a VSafeString.
Sourcepub fn as_bytes(&self) -> Option<&VBytes>
pub fn as_bytes(&self) -> Option<&VBytes>
Gets a reference to this value as VBytes. Returns None if not bytes.
Sourcepub fn as_bytes_mut(&mut self) -> Option<&mut VBytes>
pub fn as_bytes_mut(&mut self) -> Option<&mut VBytes>
Gets a mutable reference to this value as VBytes.
Sourcepub fn as_array(&self) -> Option<&VArray>
pub fn as_array(&self) -> Option<&VArray>
Gets a reference to this value as a VArray. Returns None if not an array.
Sourcepub fn as_array_mut(&mut self) -> Option<&mut VArray>
pub fn as_array_mut(&mut self) -> Option<&mut VArray>
Gets a mutable reference to this value as a VArray.
Sourcepub fn as_object(&self) -> Option<&VObject>
pub fn as_object(&self) -> Option<&VObject>
Gets a reference to this value as a VObject. Returns None if not an object.
Sourcepub fn as_object_mut(&mut self) -> Option<&mut VObject>
pub fn as_object_mut(&mut self) -> Option<&mut VObject>
Gets a mutable reference to this value as a VObject.
Sourcepub fn as_datetime(&self) -> Option<&VDateTime>
pub fn as_datetime(&self) -> Option<&VDateTime>
Gets a reference to this value as a VDateTime. Returns None if not a datetime.
Sourcepub fn as_datetime_mut(&mut self) -> Option<&mut VDateTime>
pub fn as_datetime_mut(&mut self) -> Option<&mut VDateTime>
Gets a mutable reference to this value as a VDateTime.
Sourcepub fn as_qname(&self) -> Option<&VQName>
pub fn as_qname(&self) -> Option<&VQName>
Gets a reference to this value as a VQName. Returns None if not a qualified name.
Sourcepub fn as_qname_mut(&mut self) -> Option<&mut VQName>
pub fn as_qname_mut(&mut self) -> Option<&mut VQName>
Gets a mutable reference to this value as a VQName.
Sourcepub fn as_uuid(&self) -> Option<&VUuid>
pub fn as_uuid(&self) -> Option<&VUuid>
Gets a reference to this value as a VUuid. Returns None if not a UUID.
Sourcepub fn as_uuid_mut(&mut self) -> Option<&mut VUuid>
pub fn as_uuid_mut(&mut self) -> Option<&mut VUuid>
Gets a mutable reference to this value as a VUuid.
Source§impl Value
impl Value
Sourcepub fn destructure(self) -> Destructured
pub fn destructure(self) -> Destructured
Destructure this value into an enum for pattern matching (by ownership).
Sourcepub fn destructure_ref(&self) -> DestructuredRef<'_>
pub fn destructure_ref(&self) -> DestructuredRef<'_>
Destructure this value into an enum for pattern matching (by reference).
Sourcepub fn destructure_mut(&mut self) -> DestructuredMut<'_>
pub fn destructure_mut(&mut self) -> DestructuredMut<'_>
Destructure this value into an enum for pattern matching (by mutable reference).
Trait Implementations§
Source§impl AsMut<Value> for VSafeString
impl AsMut<Value> for VSafeString
Source§impl AsRef<Value> for VSafeString
impl AsRef<Value> for VSafeString
Source§impl From<VSafeString> for Value
impl From<VSafeString> for Value
Source§fn from(s: VSafeString) -> Self
fn from(s: VSafeString) -> Self
Source§impl<K: Into<VString>, V: Into<Value>> FromIterator<(K, V)> for Value
Available on crate feature alloc only.
impl<K: Into<VString>, V: Into<Value>> FromIterator<(K, V)> for Value
alloc only.Source§fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self
Collect key-value pairs into an object Value.
Source§impl<T: Into<Value>> FromIterator<T> for Value
Available on crate feature alloc only.
impl<T: Into<Value>> FromIterator<T> for Value
alloc only.Source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Collect into an array Value.
Source§impl PartialOrd for Value
impl PartialOrd for Value
impl Eq for Value
impl Send for Value
impl Sync for Value
Auto Trait Implementations§
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.