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

True if the value is neither null nor false.

If the value is integer, return it, else fail.

If the value is a string, return it, else fail.

Return 0 for null, the absolute value for numbers, and the length for strings, arrays, and objects.

Fail on booleans.

Apply a rounding function to floating-point numbers, then convert them to integers.

Return integers unchanged, and fail on any other input.

Return true if value | .[key] is defined.

Fail on values that are neither null, arrays, nor objects.

Return any key for which value | .[key] is defined.

Fail on values that are neither arrays nor objects.

Return the elements of an array or the values of an object (omitting its keys).

Fail on any other value.

a contains b iff either

  • the string b is a substring of a,
  • every element in the array b is contained in some element of the array a,
  • for every key-value pair k, v in b, there is a key-value pair k, v' in a such that v' contains v, or
  • a equals b`.

Convert string to JSON.

Fail on any other value.

Convert a string into an array of its Unicode codepoints.

Convert an array of Unicode codepoints into a string.

Apply a function to a string.

Apply a function to an array.

Sort array by the given function.

Fail on any other value.

Split a string by a given separator string.

Fail if any of the two given values is not a string.

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the - operator.

Performs the unary - operation. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

The resulting type after applying the % operator.

Performs the % operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

The number of items that this chain link consists of.

Append the elements in this link to the chain.

An iterator over the items within this container, by value.

Iterate over the elements of the container (using internal iteration because GATs are unstable).

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

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.