pub struct JsonPathEvalContext { /* private fields */ }Expand description
What an evaluation can reuse from one node, document or query to the next.
The library keeps no state of its own. Whatever is worth reusing lives in a context that
the caller creates, passes to JpQuery::execute_with_context and drops when it is no
longer needed. The default context reuses nothing.
use jsonpath_rust::parser::parse_json_path;
use jsonpath_rust::query::JsonPathEvalContext;
use serde_json::json;
let query = parse_json_path("$[?search(@.title, 'of')]")?;
let mut ctx = JsonPathEvalContext::with_regex_cache();
let first = json!([{"title": "Sayings of the Century"}, {"title": "Moby Dick"}]);
let second = json!([{"title": "Sword of Honour"}]);
// The pattern is compiled once for the three titles.
assert_eq!(query.execute_with_context(&first, &mut ctx)?.len(), 1);
assert_eq!(query.execute_with_context(&second, &mut ctx)?.len(), 1);Implementations§
Source§impl JsonPathEvalContext
impl JsonPathEvalContext
Sourcepub fn with_regex_cache() -> Self
pub fn with_regex_cache() -> Self
A context that keeps the patterns match() and search() compile, so that a pattern
is compiled once instead of once per node.
It keeps the 8 patterns used last, whichever queries and documents they come from.
Trait Implementations§
Source§impl Clone for JsonPathEvalContext
impl Clone for JsonPathEvalContext
Source§impl Debug for JsonPathEvalContext
impl Debug for JsonPathEvalContext
Auto Trait Implementations§
impl Forget for JsonPathEvalContext
impl Freeze for JsonPathEvalContext
impl Move for JsonPathEvalContext
impl RefUnwindSafe for JsonPathEvalContext
impl Send for JsonPathEvalContext
impl Sync for JsonPathEvalContext
impl Unpin for JsonPathEvalContext
impl UnsafeUnpin for JsonPathEvalContext
impl UnwindSafe for JsonPathEvalContext
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