pub trait JsonLike:
Default
+ Clone
+ Debug
+ for<'a> From<&'a str>
+ From<Vec<String>>
+ From<bool>
+ From<i64>
+ From<f64>
+ From<Vec<Self>>
+ From<String>
+ PartialEq
+ 'static {
Show 18 methods
// Required methods
fn get(&self, key: &str) -> Option<&Self>;
fn itre(&self, pref: String) -> Vec<JsonPathValue<'_, Self>>;
fn array_len(&self) -> JsonPathValue<'static, Self>;
fn init_with_usize(cnt: usize) -> Self;
fn deep_flatten(&self, pref: String) -> Vec<(&Self, String)>;
fn deep_path_by_key<'a>(
&'a self,
key: ObjectField<'a, Self>,
pref: String,
) -> Vec<(&'a Self, String)>;
fn as_u64(&self) -> Option<u64>;
fn is_array(&self) -> bool;
fn as_array(&self) -> Option<&Vec<Self>>;
fn size(left: Vec<&Self>, right: Vec<&Self>) -> bool;
fn sub_set_of(left: Vec<&Self>, right: Vec<&Self>) -> bool;
fn any_of(left: Vec<&Self>, right: Vec<&Self>) -> bool;
fn regex(left: Vec<&Self>, right: Vec<&Self>) -> bool;
fn inside(left: Vec<&Self>, right: Vec<&Self>) -> bool;
fn less(left: Vec<&Self>, right: Vec<&Self>) -> bool;
fn eq(left: Vec<&Self>, right: Vec<&Self>) -> bool;
fn null() -> Self;
fn array(data: Vec<Self>) -> Self;
}
Expand description
The JsonLike
trait defines a set of methods and associated types for working with JSON-like data structures.
It provides a common interface for accessing and manipulating JSON data, allowing for operations such as
- retrieving values by key,
- iterating over elements
- performing various comparisons and transformations.
The trait is implemented for the serde_json::Value
type already
Required Methods§
Sourcefn get(&self, key: &str) -> Option<&Self>
fn get(&self, key: &str) -> Option<&Self>
Retrieves a reference to the value associated with the given key.
Sourcefn itre(&self, pref: String) -> Vec<JsonPathValue<'_, Self>>
fn itre(&self, pref: String) -> Vec<JsonPathValue<'_, Self>>
Iterates over the elements with a given prefix and returns a vector of JsonPathValue
.
Sourcefn array_len(&self) -> JsonPathValue<'static, Self>
fn array_len(&self) -> JsonPathValue<'static, Self>
Returns the length of the array as a JsonPathValue
.
Sourcefn init_with_usize(cnt: usize) -> Self
fn init_with_usize(cnt: usize) -> Self
Initializes an instance with a specific size.
Sourcefn deep_flatten(&self, pref: String) -> Vec<(&Self, String)>
fn deep_flatten(&self, pref: String) -> Vec<(&Self, String)>
Flattens nested structures and returns a vector of tuples containing references to the elements and their paths.
Sourcefn deep_path_by_key<'a>(
&'a self,
key: ObjectField<'a, Self>,
pref: String,
) -> Vec<(&'a Self, String)>
fn deep_path_by_key<'a>( &'a self, key: ObjectField<'a, Self>, pref: String, ) -> Vec<(&'a Self, String)>
Performs a deep search by key and returns a vector of tuples containing references to the elements and their paths.
Sourcefn size(left: Vec<&Self>, right: Vec<&Self>) -> bool
fn size(left: Vec<&Self>, right: Vec<&Self>) -> bool
Compares the size of two vectors of references to elements.
Sourcefn sub_set_of(left: Vec<&Self>, right: Vec<&Self>) -> bool
fn sub_set_of(left: Vec<&Self>, right: Vec<&Self>) -> bool
Checks if the left vector is a subset of the right vector.
Sourcefn any_of(left: Vec<&Self>, right: Vec<&Self>) -> bool
fn any_of(left: Vec<&Self>, right: Vec<&Self>) -> bool
Checks if any element in the left vector is present in the right vector.
Sourcefn regex(left: Vec<&Self>, right: Vec<&Self>) -> bool
fn regex(left: Vec<&Self>, right: Vec<&Self>) -> bool
Checks if the elements in the left vector match the regex pattern in the right vector.
Sourcefn inside(left: Vec<&Self>, right: Vec<&Self>) -> bool
fn inside(left: Vec<&Self>, right: Vec<&Self>) -> bool
Checks if any element in the left vector is inside the right vector.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl JsonLike for Value
impl JsonLike for Value
Source§fn less(left: Vec<&Self>, right: Vec<&Self>) -> bool
fn less(left: Vec<&Self>, right: Vec<&Self>) -> bool
ensure the number on the left side is less the number on the right side