pub struct JSONQuery {
pub elements: Vec<QueryElement>,
}
Expand description
This is the main interface to this library. Create a new JSONQuery by calling parse.
Fields§
§elements: Vec<QueryElement>
A list of access-elements, field names or array indices.
Implementations§
Source§impl JSONQuery
impl JSONQuery
Sourcepub fn parse(input: &str) -> Result<Self, QueryParseErr>
pub fn parse(input: &str) -> Result<Self, QueryParseErr>
Construct a new JSONQuery object from an example string.
use access_json::JSONQuery;
use access_json::query::QueryElement; // Only needed to validate our parsing.
assert_eq!(
JSONQuery::parse(".field.array[8]").unwrap().elements,
vec![QueryElement::field("field"),
QueryElement::field("array"),
QueryElement::array_item(8)]);
Sourcepub fn execute(
&self,
target: &dyn AnySerializable,
) -> Result<Option<Value>, QueryExecErr>
pub fn execute( &self, target: &dyn AnySerializable, ) -> Result<Option<Value>, QueryExecErr>
Execute a JSONQuery object against any serde-serializable object.
use access_json::JSONQuery;
use std::collections::HashMap;
use serde_json;
let mut data: HashMap<&str, u32> = HashMap::default();
data.insert("cat", 9);
let query = JSONQuery::parse(".cat")?;
let output = query.execute(&data)?;
let expected = serde_json::to_value(&9)?;
assert_eq!(Some(expected), output);
Trait Implementations§
Source§impl<'de> Deserialize<'de> for JSONQuery
impl<'de> Deserialize<'de> for JSONQuery
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for JSONQuery
This is a way to visualize a JSONQuery object as a parse-able string.
impl Display for JSONQuery
This is a way to visualize a JSONQuery object as a parse-able string.
impl Eq for JSONQuery
impl StructuralPartialEq for JSONQuery
Auto Trait Implementations§
impl Freeze for JSONQuery
impl RefUnwindSafe for JSONQuery
impl Send for JSONQuery
impl Sync for JSONQuery
impl Unpin for JSONQuery
impl UnwindSafe for JSONQuery
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
Mutably borrows from an owned value. Read more