pub enum Val {
Null,
Bool(bool),
Int(isize),
Float(f64),
Num(Rc<Number>),
Str(Rc<String>),
Arr(Rc<Vec<Val>>),
Obj(Rc<IndexMap<Rc<String>, Val, RandomState>>),
}Expand description
JSON value with sharing.
The speciality of this type is that numbers are distinguished into machine-sized integers and 64-bit floating-point numbers. This allows using integers to index arrays, while using floating-point numbers to do general math.
Operations on numbers follow a few principles:
- The sum, difference, product, and remainder of two integers is integer.
- Any other operation between two numbers yields a float.
Variants
Null
Null
Bool(bool)
Boolean
Int(isize)
Integer
Float(f64)
Floating-point number
Num(Rc<Number>)
Floating-point number or integer not fitting into Int
Str(Rc<String>)
String
Arr(Rc<Vec<Val>>)
Array
Obj(Rc<IndexMap<Rc<String>, Val, RandomState>>)
Order-preserving map
Implementations
sourceimpl Val
impl Val
sourcepub fn len(&self) -> Result<Self, Error>
pub fn len(&self) -> Result<Self, Error>
Return 0 for null, the absolute value for numbers, and the length for strings, arrays, and objects.
Fail on booleans.
sourcepub fn round(&self, f: impl FnOnce(f64) -> f64) -> Result<Self, Error>
pub fn round(&self, f: impl FnOnce(f64) -> f64) -> Result<Self, Error>
Apply a rounding function to floating-point numbers, then convert them to integers.
Return integers unchanged, and fail on any other input.
sourcepub fn has(&self, key: &Self) -> Result<bool, Error>
pub fn has(&self, key: &Self) -> Result<bool, Error>
Return true if value | .[key] is defined.
Fail on values that are neither null, arrays, nor objects.
sourcepub fn keys(&self) -> Result<Vec<Val>, Error>
pub fn keys(&self) -> Result<Vec<Val>, Error>
Return any key for which value | .[key] is defined.
Fail on values that are neither arrays nor objects.
sourcepub fn iter(&self) -> Result<Box<dyn Iterator<Item = Val> + '_>, Error>
pub fn iter(&self) -> Result<Box<dyn Iterator<Item = Val> + '_>, Error>
Return the elements of an array or the values of an object (omitting its keys).
Fail on any other value.
sourcepub fn contains(&self, other: &Self) -> bool
pub fn contains(&self, other: &Self) -> bool
a contains b iff either
- the string
bis a substring ofa, - every element in the array
bis contained in some element of the arraya, - for every key-value pair
k, vinb, there is a key-value pairk, v'inasuch thatv'containsv, or a equalsb`.
sourcepub fn explode(&self) -> Result<Vec<Val>, Error>
pub fn explode(&self) -> Result<Vec<Val>, Error>
Convert a string into an array of its Unicode codepoints.
sourcepub fn implode(&self) -> Result<String, Error>
pub fn implode(&self) -> Result<String, Error>
Convert an array of Unicode codepoints into a string.
sourcepub fn mutate_str(self, f: impl Fn(&mut String)) -> ValR
pub fn mutate_str(self, f: impl Fn(&mut String)) -> ValR
Apply a function to a string.
Trait Implementations
sourceimpl Ord for Val
impl Ord for Val
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
sourceimpl PartialOrd<Val> for Val
impl PartialOrd<Val> for Val
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moreimpl Eq for Val
Auto Trait Implementations
impl RefUnwindSafe for Val
impl !Send for Val
impl !Sync for Val
impl Unpin for Val
impl UnwindSafe for Val
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> Container<T> for Twhere
T: Clone,
impl<T> Container<T> for Twhere
T: Clone,
sourceimpl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.