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)) -> Result<Val, Error>
pub fn mutate_str(self, f: impl Fn(&mut String)) -> Result<Val, Error>
Apply a function to a string.
sourcepub fn mutate_arr(self, f: impl Fn(&mut Vec<Val>)) -> Result<Val, Error>
pub fn mutate_arr(self, f: impl Fn(&mut Vec<Val>)) -> Result<Val, Error>
Apply a function to an array.
Trait Implementations
sourceimpl Ord for Val
impl Ord for Val
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>
This method returns an ordering between self and other values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
impl 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 T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Container<T> for T where
T: Clone,
impl<T> Container<T> for T where
T: Clone,
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key and return true if they are equal.
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more