Skip to main content

Value

Enum Value 

Source
pub enum Value {
    Null,
    Bool(bool),
    Int(i64),
    Float(f64),
    Str(String),
    Array(Vec<Value>),
    Object(Vec<(String, Value)>),
}

Variants§

§

Null

§

Bool(bool)

§

Int(i64)

§

Float(f64)

§

Str(String)

§

Array(Vec<Value>)

§

Object(Vec<(String, Value)>)

Implementations§

Source§

impl Value

Source

pub fn is_truthy(&self) -> bool

jq-style truthiness: only false and null are falsy.

Source

pub fn type_name(&self) -> &'static str

The type name, as reported by the type builtin.

Source

pub fn as_f64(&self) -> Option<f64>

Numeric coercion to f64 for arithmetic and comparison.

Source

pub fn order(&self, other: &Value) -> Ordering

Total order across types (jq’s ordering: null < bool < number < string < array < object).

Source

pub fn value_eq(&self, other: &Value) -> bool

Structural equality consistent with Value::order.

Source

pub fn to_raw_string(&self) -> String

Render as a raw scalar for query output (no surrounding quotes on strings). Composite values are rendered as JSON.

Source

pub fn to_json(&self) -> String

Render as compact JSON.

Source

pub fn to_json5(&self) -> String

Render as compact JSON in the JSON5 spelling: non-finite floats keep their Infinity / -Infinity / NaN literals instead of degrading to null. This is what the JSONC/JSON5-family emitters use, so converting or querying a JSON5 source with a non-finite number preserves it; strict JSON must use Value::to_json (which, like JSON.stringify, encodes one as null).

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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<T: Into<Value> + Clone> From<&[T]> for Value

Source§

fn from(input: &[T]) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for Value

Source§

fn from(input: &str) -> Self

Converts to this type from the input type.
Source§

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

None is JSON’s null; Some(v) is whatever v converts to.

Source§

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

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(input: String) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(input: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(input: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Value

Source§

fn from(input: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(input: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for Value

Source§

fn from(input: i8) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Value

Source§

fn from(input: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(input: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(input: i64) -> Self

Converts to this type from the input type.
Source§

impl From<isize> for Value

Source§

fn from(input: isize) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Value

Source§

fn from(input: u8) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Value

Source§

fn from(input: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(input: u32) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self

Collect key-value pairs into an object, preserving iteration order.

Source§

impl PartialEq for Value

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin for Value

§

impl UnwindSafe for Value

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

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

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.