pub struct Document { /* private fields */ }Expand description
A JSON document in jlens’s internal representation.
Every evaluate call converts the parts of its input document that the expression reads
from serde_json::Value, one level at a time. An expression that reads most of a large
document can spend more on that than on the evaluation itself. To evaluate several
expressions (a set of rules, say) or the same one several times against one document,
convert it once into a Document and use
Expression::evaluate_document.
use jlens_core::{Bindings, Document, Expression, Options};
let doc = Document::parse(r#"{"items": [{"price": 2}, {"price": 3}]}"#).unwrap();
let rules = ["$sum(items.price) > 4", "$count(items) < 10"];
for rule in rules {
let expr = Expression::compile(rule).unwrap();
let result = expr.evaluate_document(&doc, &Bindings::new(), &Options::default());
assert_eq!(result.unwrap(), Some(serde_json::json!(true)));
}Evaluations never modify the document. The one exception is a transform (|...|) whose
expression rebinds $clone to a function that does not copy its argument.
A Document is not Send. Convert it on the thread that evaluates against it.
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Document
impl !Send for Document
impl !Sync for Document
impl !UnwindSafe for Document
impl Freeze for Document
impl Unpin for Document
impl UnsafeUnpin for Document
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