pub enum Value {
    Array(Vec<Value>),
    Boolean(bool),
    Null,
    Number(Number),
    String(String),
    Object(Map<String, Value>),
    Expression(AST),
}
Expand description

Represents any valid value that is processed during evaluation of a JMESPath expression or used as an argument to a JMESPath Function.

Values are specified at runtime when calling the function. They must match the function’s signature.

Variants§

§

Array(Vec<Value>)

Represents a valid JSON array.

Example

use jmespath_community as jmespath;
use jmespath::Value;
let value: Value = vec![1, 2, 3].into();
assert!(matches!(value, Value::Array(..)));
§

Boolean(bool)

Represents a valid JSON boolean.

Example

use jmespath_community as jmespath;
use jmespath::Value;
let value: Value = true.into();
assert!(matches!(value, Value::Boolean(true)));
§

Null

Represents a valid JSON null token.

Example

use jmespath_community as jmespath;
use jmespath::Value;
let value: Value = None.into();
assert!(matches!(value, Value::Null));
§

Number(Number)

Represents a valid JSON number.

Example

use jmespath_community as jmespath;
use jmespath::Value;
use jmespath::Number;
let value: Value = 42.into();
assert!(matches!(value, Value::Number(..)));
§

String(String)

Represents a valid JSON string.

Example

use jmespath_community as jmespath;
use jmespath::Value;
let value: Value = "text".into();
assert!(matches!(value, Value::String(..)));
§

Object(Map<String, Value>)

Represents a valid JSON object.

Example

use jmespath_community as jmespath;
use jmespath::{Map, Value};
use jmespath::map;
let value: Value = map!("foo" => "bar").into();
assert!(matches!(value, Value::Object(..)));
§

Expression(AST)

Represents a JMESPath expression.

Implementations§

source§

impl Value

source

pub fn from_f64(number: f64) -> Result<Self, Error>

source

pub fn map_from_json(value: &Value) -> Value

Converts a serde_json::Value to a Value.

Example
use jmespath_community as jmespath;
use jmespath::Value;
use serde_json::json;

let s = json!({"foo": "bar"});
let v = Value::map_from_json(&s);
assert!(matches!(v, Value::Object(..)));
source

pub fn from_json(text: &str) -> Result<Self, Error>

Creates a Value from a JSON representation.

Convenience function that uses serde_json to convert a JSON representation to a Value.

Example
use jmespath_community as jmespath;
use jmespath::Value;

let value = Value::from_json(r#"{"foo": "bar"}"#).unwrap();
assert!(value.is_object());
source

pub fn to_json(&self) -> String

Returns the JSON string representation for this Value.

Example
use jmespath_community as jmespath;
use jmespath::Value;

assert_eq!("null", Value::Null.to_json());
assert_eq!("\"text\"", Value::String("text".to_string()).to_json());
source

pub fn get_data_type(&self) -> DataType

Returns the corresponding DataType

Example
use jmespath_community as jmespath;
use jmespath::Value;
use jmespath::functions::DataType;

let arg = Value::from_f64(42.0).unwrap();
assert_eq!(DataType::Number, arg.get_data_type());
source

pub fn map_into<T>(vec: Vec<T>) -> Vec<Self>where T: Into<Value>,

Converts a Vec<T> to a Vec<Value>

Example
use jmespath_community as jmespath;
use jmespath::Value;
let vec: Vec<Value> = Value::map_into(vec![1, 2]);
 assert!(vec.iter().all(|x| matches!(x, Value::Number(..))));
source

pub fn as_array(&self) -> Option<&Vec<Value>>

Returns an Option<&Vec<Value>> of the corresponding type.

source

pub fn as_expref(&self) -> Option<&AST>

Returns an Option<&AST> of the corresponding type.

source

pub fn as_number(&self) -> Option<&Number>

Returns an Option<&Number> of the corresponding type.

source

pub fn as_object(&self) -> Option<&Map<String, Value>>

Returns an Option<&Map<String, Value>> of the corresponding type.

source

pub fn as_str(&self) -> Option<&str>

Returns an Option<&str> of the corresponding type.

source

pub fn as_bool(&self) -> Option<bool>

Returns an Option<bool> of the corresponding type.

source

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

Returns an Option<f64> of the corresponding type.

source

pub fn if_array(&self) -> Option<Value>

Returns Option<Value> if the Value is if_array .

source

pub fn if_object(&self) -> Option<Value>

Returns Option<Value> if the Value is if_object .

source

pub fn is_null(&self) -> bool

Returns true if the Value is the null value.

source

pub fn is_array(&self) -> bool

Returns true if the Value is a value from type Value::Array.

source

pub fn is_bool(&self) -> bool

Returns true if the Value is a value from type Value::Boolean.

source

pub fn is_number(&self) -> bool

Returns true if the Value is a value from type Value::Number.

source

pub fn is_object(&self) -> bool

Returns true if the Value is a value from type Value::Object.

source

pub fn is_str(&self) -> bool

Returns true if the Value is a value from type Value::String.

source

pub fn is_expression(&self) -> bool

Returns true if the Value is a value from type Value::Expression.

source

pub fn is_true(&self) -> bool

Returns true if the Value is the boolean true.

source

pub fn is_false(&self) -> bool

Returns false if the Value is the boolean false.

source

pub fn is_falsy(&self) -> bool

Returns true if the Value is either:

  • the null value
  • the boolean false
  • the empty string ""
  • an empty array []
  • an empty object {}
source

pub fn is_truthy(&self) -> bool

Returns true if the Value is not a falsy value. This is the opposite to the Value::is_falsy() function.

Trait Implementations§

source§

impl Clone for Value

source§

fn clone(&self) -> Value

Returns a copy of the value. Read more
1.0.0 · 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 Display for Value

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<&String> for Value

source§

fn from(v: &String) -> Self

Converts to this type from the input type.
source§

impl From<&str> for Value

source§

fn from(v: &str) -> Self

Converts to this type from the input type.
source§

impl<V> From<BTreeMap<&str, V, Global>> for Valuewhere V: Into<Value>,

source§

fn from(v: Map<&str, V>) -> Self

Converts to this type from the input type.
source§

impl From<Number> for Value

source§

fn from(number: Number) -> Self

Converts to this type from the input type.
source§

impl From<Option<()>> for Value

source§

fn from(_: Option<()>) -> Self

Converts to this type from the input type.
source§

impl From<String> for Value

source§

fn from(v: String) -> Self

Converts to this type from the input type.
source§

impl<T> From<Vec<T, Global>> for Valuewhere T: Into<Value>,

source§

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

Converts to this type from the input type.
source§

impl From<bool> for Value

source§

fn from(v: bool) -> Self

Converts to this type from the input type.
source§

impl From<i16> for Value

source§

fn from(v: i16) -> Self

Converts to this type from the input type.
source§

impl From<i32> for Value

source§

fn from(v: i32) -> Self

Converts to this type from the input type.
source§

impl From<i8> for Value

source§

fn from(v: i8) -> Self

Converts to this type from the input type.
source§

impl From<isize> for Value

source§

fn from(v: isize) -> Self

Converts to this type from the input type.
source§

impl From<u16> for Value

source§

fn from(v: u16) -> Self

Converts to this type from the input type.
source§

impl From<u32> for Value

source§

fn from(v: u32) -> Self

Converts to this type from the input type.
source§

impl From<u8> for Value

source§

fn from(v: u8) -> Self

Converts to this type from the input type.
source§

impl From<usize> for Value

source§

fn from(v: usize) -> Self

Converts to this type from the input type.
source§

impl PartialEq<&str> for Value

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Option<()>> for Value

source§

fn eq(&self, _: &Option<()>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<String> for Value

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Value> for &str

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Value> for Option<()>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Value> for String

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Value> for Value

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Value> for bool

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Value> for f32

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Value> for f64

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Value> for i16

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Value> for i32

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Value> for i64

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Value> for i8

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Value> for isize

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Value> for u16

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Value> for u32

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Value> for u64

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Value> for u8

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Value> for usize

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<bool> for Value

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<f32> for Value

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<f64> for Value

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<i16> for Value

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<i32> for Value

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<i64> for Value

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<i8> for Value

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<isize> for Value

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<u16> for Value

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<u32> for Value

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<u64> for Value

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<u8> for Value

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<usize> for Value

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Value

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Value

Auto Trait Implementations§

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnwindSafe for Value

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

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

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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 Twhere T: Clone,

§

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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.