pub enum Val {
Null,
Bool(bool),
Int(isize),
Float(f64),
Num(Rc<String>),
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<String>)
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>>)
Object
Implementations§
Source§impl Val
impl Val
Sourcepub fn parse(token: Token, lexer: &mut impl LexAlloc) -> Result<Self, Error>
pub fn parse(token: Token, lexer: &mut impl LexAlloc) -> Result<Self, Error>
Parse at least one JSON value, given an initial token and a lexer.
If the underlying lexer reads input fallibly (for example IterLexer),
the error returned by this function might be misleading.
In that case, always check whether the lexer contains an error.
Trait Implementations§
Source§impl FromIterator<Val> for Val
impl FromIterator<Val> for Val
Source§fn from_iter<T: IntoIterator<Item = Self>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = Self>>(iter: T) -> Self
Creates a value from an iterator. Read more
Source§impl Ord for Val
impl Ord for Val
Source§impl PartialOrd for Val
impl PartialOrd for Val
Source§impl ValT for Val
impl ValT for Val
Source§fn from_map<I: IntoIterator<Item = (Self, Self)>>(iter: I) -> ValR
fn from_map<I: IntoIterator<Item = (Self, Self)>>(iter: I) -> ValR
Create an associative map (or object) from a sequence of key-value pairs. Read more
Source§fn range(self, range: Range<&Self>) -> ValR
fn range(self, range: Range<&Self>) -> ValR
Yield a slice of the value with the given range. Read more
Source§fn map_values<'a, I: Iterator<Item = ValX<'a>>>(
self,
opt: Opt,
f: impl Fn(Self) -> I,
) -> ValX<'a>
fn map_values<'a, I: Iterator<Item = ValX<'a>>>( self, opt: Opt, f: impl Fn(Self) -> I, ) -> ValX<'a>
Map a function over the children of the value. Read more
impl Eq for Val
Auto Trait Implementations§
impl Freeze for Val
impl RefUnwindSafe for Val
impl !Send for Val
impl !Sync for Val
impl Unpin for Val
impl UnwindSafe for Val
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
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
Compare self to
key and return true if they are equal.