[][src]Struct jsonpath_lib::Compiled

pub struct Compiled { /* fields omitted */ }

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

impl Compiled[src]

pub fn compile(path: &str) -> Result<Compiled, String>[src]

Compile a path expression and return a compiled instance.

If parsing the path fails, it will return an error.

pub fn select<'a>(
    &self,
    value: &'a Value
) -> Result<Vec<&'a Value>, JsonPathError>
[src]

Execute the select operation on the pre-compiled path.

Trait Implementations

impl Clone for Compiled[src]

impl Debug for Compiled[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.