Value

Struct Value 

Source
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

Source

pub const NULL: Self

JSON null value.

Source

pub const FALSE: Self

JSON false value.

Source

pub const TRUE: Self

JSON true value.

Source

pub fn value_type(&self) -> ValueType

Returns the type of this value.

Source

pub fn is_null(&self) -> bool

Returns true if this is the null value.

Source

pub fn is_bool(&self) -> bool

Returns true if this is a boolean.

Source

pub fn is_true(&self) -> bool

Returns true if this is true.

Source

pub fn is_false(&self) -> bool

Returns true if this is false.

Source

pub fn is_number(&self) -> bool

Returns true if this is a number.

Source

pub fn is_string(&self) -> bool

Returns true if this is a string.

Source

pub fn is_bytes(&self) -> bool

Returns true if this is bytes.

Source

pub fn is_array(&self) -> bool

Returns true if this is an array.

Source

pub fn is_object(&self) -> bool

Returns true if this is an object.

Source

pub fn is_datetime(&self) -> bool

Returns true if this is a datetime.

Source

pub fn is_qname(&self) -> bool

Returns true if this is a qualified name.

Source

pub fn is_uuid(&self) -> bool

Returns true if this is a UUID.

Source

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

Converts this value to a bool. Returns None if not a boolean.

Source

pub fn as_number(&self) -> Option<&VNumber>

Gets a reference to this value as a VNumber. Returns None if not a number.

Source

pub fn as_number_mut(&mut self) -> Option<&mut VNumber>

Gets a mutable reference to this value as a VNumber.

Source

pub fn as_string(&self) -> Option<&VString>

Gets a reference to this value as a VString. Returns None if not a string.

Source

pub fn as_string_mut(&mut self) -> Option<&mut VString>

Gets a mutable reference to this value as a VString.

Source

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.

Source

pub fn as_safe_string(&self) -> Option<&VSafeString>

Gets a reference to this value as a VSafeString. Returns None if not a safe string.

Source

pub fn as_safe_string_mut(&mut self) -> Option<&mut VSafeString>

Gets a mutable reference to this value as a VSafeString.

Source

pub fn as_bytes(&self) -> Option<&VBytes>

Gets a reference to this value as VBytes. Returns None if not bytes.

Source

pub fn as_bytes_mut(&mut self) -> Option<&mut VBytes>

Gets a mutable reference to this value as VBytes.

Source

pub fn as_array(&self) -> Option<&VArray>

Gets a reference to this value as a VArray. Returns None if not an array.

Source

pub fn as_array_mut(&mut self) -> Option<&mut VArray>

Gets a mutable reference to this value as a VArray.

Source

pub fn as_object(&self) -> Option<&VObject>

Gets a reference to this value as a VObject. Returns None if not an object.

Source

pub fn as_object_mut(&mut self) -> Option<&mut VObject>

Gets a mutable reference to this value as a VObject.

Source

pub fn as_datetime(&self) -> Option<&VDateTime>

Gets a reference to this value as a VDateTime. Returns None if not a datetime.

Source

pub fn as_datetime_mut(&mut self) -> Option<&mut VDateTime>

Gets a mutable reference to this value as a VDateTime.

Source

pub fn as_qname(&self) -> Option<&VQName>

Gets a reference to this value as a VQName. Returns None if not a qualified name.

Source

pub fn as_qname_mut(&mut self) -> Option<&mut VQName>

Gets a mutable reference to this value as a VQName.

Source

pub fn as_uuid(&self) -> Option<&VUuid>

Gets a reference to this value as a VUuid. Returns None if not a UUID.

Source

pub fn as_uuid_mut(&mut self) -> Option<&mut VUuid>

Gets a mutable reference to this value as a VUuid.

Source

pub fn take(&mut self) -> Value

Takes this value, replacing it with Value::NULL.

Source§

impl Value

Source

pub fn destructure(self) -> Destructured

Destructure this value into an enum for pattern matching (by ownership).

Source

pub fn destructure_ref(&self) -> DestructuredRef<'_>

Destructure this value into an enum for pattern matching (by reference).

Source

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 VArray

Source§

fn as_mut(&mut self) -> &mut Value

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsMut<Value> for VBytes

Source§

fn as_mut(&mut self) -> &mut Value

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsMut<Value> for VNumber

Source§

fn as_mut(&mut self) -> &mut Value

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsMut<Value> for VObject

Source§

fn as_mut(&mut self) -> &mut Value

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsMut<Value> for VSafeString

Source§

fn as_mut(&mut self) -> &mut Value

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsMut<Value> for VString

Source§

fn as_mut(&mut self) -> &mut Value

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<Value> for VArray

Source§

fn as_ref(&self) -> &Value

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<Value> for VBytes

Source§

fn as_ref(&self) -> &Value

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<Value> for VNumber

Source§

fn as_ref(&self) -> &Value

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<Value> for VObject

Source§

fn as_ref(&self) -> &Value

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<Value> for VSafeString

Source§

fn as_ref(&self) -> &Value

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<Value> for VString

Source§

fn as_ref(&self) -> &Value

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Value

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Value

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for Value

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Facet<'_> for Value

Source§

const SHAPE: &'static Shape

The shape of this type, including: whether it’s a Struct, an Enum, something else? Read more
Source§

impl From<&[u8]> for Value

Available on crate feature alloc only.
Source§

fn from(data: &[u8]) -> Self

Converts to this type from the input type.
Source§

impl From<&String> for Value

Available on crate feature alloc only.
Source§

fn from(s: &String) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for Value

Available on crate feature alloc only.
Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Value>> From<Option<T>> for Value

Source§

fn from(opt: Option<T>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Available on crate feature alloc only.
Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<VArray> for Value

Source§

fn from(arr: VArray) -> Self

Converts to this type from the input type.
Source§

impl From<VBytes> for Value

Source§

fn from(b: VBytes) -> Self

Converts to this type from the input type.
Source§

impl From<VDateTime> for Value

Available on crate feature alloc only.
Source§

fn from(dt: VDateTime) -> Self

Converts to this type from the input type.
Source§

impl From<VNumber> for Value

Source§

fn from(n: VNumber) -> Self

Converts to this type from the input type.
Source§

impl From<VObject> for Value

Source§

fn from(obj: VObject) -> Self

Converts to this type from the input type.
Source§

impl From<VQName> for Value

Available on crate feature alloc only.
Source§

fn from(qname: VQName) -> Self

Converts to this type from the input type.
Source§

impl From<VSafeString> for Value

Source§

fn from(s: VSafeString) -> Self

Converts to this type from the input type.
Source§

impl From<VString> for Value

Source§

fn from(s: VString) -> Self

Converts to this type from the input type.
Source§

impl From<VUuid> for Value

Available on crate feature alloc only.
Source§

fn from(uuid: VUuid) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for Value

Available on crate feature alloc only.
Source§

fn from(data: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(b: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Value

Available on crate feature alloc only.
Source§

fn from(v: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Available on crate feature alloc only.
Source§

fn from(v: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Value

Available on crate feature alloc only.
Source§

fn from(v: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Available on crate feature alloc only.
Source§

fn from(v: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Available on crate feature alloc only.
Source§

fn from(v: i64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for Value

Available on crate feature alloc only.
Source§

fn from(v: i8) -> Self

Converts to this type from the input type.
Source§

impl From<isize> for Value

Available on crate feature alloc only.
Source§

fn from(v: isize) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Value

Available on crate feature alloc only.
Source§

fn from(v: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Value

Available on crate feature alloc only.
Source§

fn from(v: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Value

Available on crate feature alloc only.
Source§

fn from(v: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Value

Available on crate feature alloc only.
Source§

fn from(v: u8) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for Value

Available on crate feature alloc only.
Source§

fn from(v: usize) -> Self

Converts to this type from the input type.
Source§

impl<K: Into<VString>, V: Into<Value>> FromIterator<(K, V)> for Value

Available on crate feature alloc only.
Source§

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.
Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Collect into an array Value.

Source§

impl Hash for Value

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Value

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for Value

Source§

impl Send for Value

Source§

impl Sync for Value

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V