Enum jmespath_community::Value
source · 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
impl Value
pub fn from_f64(number: f64) -> Result<Self, Error>
sourcepub fn map_from_json(value: &Value) -> Value
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(..)));
sourcepub fn get_data_type(&self) -> DataType
pub fn get_data_type(&self) -> DataType
sourcepub fn map_into<T>(vec: Vec<T>) -> Vec<Self>where
T: Into<Value>,
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(..))));
sourcepub fn as_array(&self) -> Option<&Vec<Value>>
pub fn as_array(&self) -> Option<&Vec<Value>>
Returns an
Option<&Vec<Value>>
of the corresponding type.
sourcepub fn as_expref(&self) -> Option<&AST>
pub fn as_expref(&self) -> Option<&AST>
Returns an
Option<&AST>
of the corresponding type.
sourcepub fn as_number(&self) -> Option<&Number>
pub fn as_number(&self) -> Option<&Number>
Returns an
Option<&Number>
of the corresponding type.
sourcepub fn as_object(&self) -> Option<&Map<String, Value>>
pub fn as_object(&self) -> Option<&Map<String, Value>>
Returns an
Option<&Map<String, Value>>
of the corresponding type.
sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Returns an
Option<&str>
of the corresponding type.
sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
Returns an
Option<bool>
of the corresponding type.
sourcepub fn as_f64(&self) -> Option<f64>
pub fn as_f64(&self) -> Option<f64>
Returns an Option<f64>
of the corresponding type.
sourcepub fn is_array(&self) -> bool
pub fn is_array(&self) -> bool
Returns true
if the Value
is a value from type
Value::Array
.
sourcepub fn is_bool(&self) -> bool
pub fn is_bool(&self) -> bool
Returns true
if the Value
is a value from type
Value::Boolean
.
sourcepub fn is_number(&self) -> bool
pub fn is_number(&self) -> bool
Returns true
if the Value
is a value from type
Value::Number
.
sourcepub fn is_object(&self) -> bool
pub fn is_object(&self) -> bool
Returns true
if the Value
is a value from type
Value::Object
.
sourcepub fn is_str(&self) -> bool
pub fn is_str(&self) -> bool
Returns true
if the Value
is a value from type
Value::String
.
sourcepub fn is_expression(&self) -> bool
pub fn is_expression(&self) -> bool
Returns true
if the Value
is a value from type
Value::Expression
.
sourcepub fn is_falsy(&self) -> bool
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
{}
sourcepub fn is_truthy(&self) -> bool
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 PartialEq<&str> for Value
impl PartialEq<&str> for Value
source§impl PartialEq<Option<()>> for Value
impl PartialEq<Option<()>> for Value
source§impl PartialEq<String> for Value
impl PartialEq<String> for Value
source§impl PartialEq<Value> for &str
impl PartialEq<Value> for &str
source§impl PartialEq<Value> for Option<()>
impl PartialEq<Value> for Option<()>
source§impl PartialEq<Value> for String
impl PartialEq<Value> for String
source§impl PartialEq<Value> for Value
impl PartialEq<Value> for Value
source§impl PartialEq<Value> for bool
impl PartialEq<Value> for bool
source§impl PartialEq<Value> for f32
impl PartialEq<Value> for f32
source§impl PartialEq<Value> for f64
impl PartialEq<Value> for f64
source§impl PartialEq<Value> for i16
impl PartialEq<Value> for i16
source§impl PartialEq<Value> for i32
impl PartialEq<Value> for i32
source§impl PartialEq<Value> for i64
impl PartialEq<Value> for i64
source§impl PartialEq<Value> for i8
impl PartialEq<Value> for i8
source§impl PartialEq<Value> for isize
impl PartialEq<Value> for isize
source§impl PartialEq<Value> for u16
impl PartialEq<Value> for u16
source§impl PartialEq<Value> for u32
impl PartialEq<Value> for u32
source§impl PartialEq<Value> for u64
impl PartialEq<Value> for u64
source§impl PartialEq<Value> for u8
impl PartialEq<Value> for u8
source§impl PartialEq<Value> for usize
impl PartialEq<Value> for usize
source§impl PartialEq<bool> for Value
impl PartialEq<bool> for Value
source§impl PartialEq<isize> for Value
impl PartialEq<isize> for Value
source§impl PartialEq<usize> for Value
impl PartialEq<usize> for Value
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> 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
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.