Struct jsonpath_lib::PathCompiled
source · pub struct PathCompiled<'a> { /* private fields */ }
Expand description
A pre-compiled expression.
Calling the select function of this struct will re-use the existing, compiled expression.
§Example
extern crate jsonpath_lib as jsonpath;
#[macro_use] extern crate serde_json;
let mut first_friend = jsonpath::PathCompiled::compile("$..friends[0]").unwrap();
let json_obj = json!({
"school": {
"friends": [
{"name": "친구1", "age": 20},
{"name": "친구2", "age": 20}
]
},
"friends": [
{"name": "친구3", "age": 30},
{"name": "친구4"}
]});
// call a first time
let json = first_friend.select(&json_obj).unwrap();
assert_eq!(json, vec![
&json!({"name": "친구3", "age": 30}),
&json!({"name": "친구1", "age": 20})
]);
// call a second time
let json = first_friend.select(&json_obj).unwrap();
assert_eq!(json, vec![
&json!({"name": "친구3", "age": 30}),
&json!({"name": "친구1", "age": 20})
]);
Implementations§
source§impl<'a> PathCompiled<'a>
impl<'a> PathCompiled<'a>
sourcepub fn compile(path: &str) -> Result<PathCompiled<'_>, JsonPathError>
pub fn compile(path: &str) -> Result<PathCompiled<'_>, JsonPathError>
Compile a path expression and return a compiled instance.
If parsing the path fails, it will return an error.
Trait Implementations§
source§impl<'a> Clone for PathCompiled<'a>
impl<'a> Clone for PathCompiled<'a>
source§fn clone(&self) -> PathCompiled<'a>
fn clone(&self) -> PathCompiled<'a>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl<'a> RefUnwindSafe for PathCompiled<'a>
impl<'a> !Send for PathCompiled<'a>
impl<'a> !Sync for PathCompiled<'a>
impl<'a> Unpin for PathCompiled<'a>
impl<'a> UnwindSafe for PathCompiled<'a>
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