Struct jsonpath_lib::Compiled
source · pub struct Compiled { /* private fields */ }
👎Deprecated since 0.4.0: Please use PathCompiled.
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::Compiled::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 Compiled
impl Compiled
sourcepub fn compile(path: &str) -> Result<Self, String>
pub fn compile(path: &str) -> Result<Self, String>
Compile a path expression and return a compiled instance.
If parsing the path fails, it will return an error.
sourcepub fn select<'a>(
&self,
value: &'a Value
) -> Result<Vec<&'a Value>, JsonPathError>
pub fn select<'a>( &self, value: &'a Value ) -> Result<Vec<&'a Value>, JsonPathError>
Execute the select operation on the pre-compiled path.
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Compiled
impl Send for Compiled
impl Sync for Compiled
impl Unpin for Compiled
impl UnwindSafe for Compiled
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