pub struct ParsedData(/* private fields */);Expand description
A parsed JSON document that owns its backing storage.
Accepted by every arena-lifetime evaluation entry point
(crate::Engine::evaluate, crate::Session::eval /
crate::Session::eval_borrowed, …) via crate::EvalInput at
zero per-call conversion cost — the tree is already arena-resident.
§Example
use datalogic_rs::{Engine, ParsedData};
use datalogic_rs::bumpalo::Bump;
let engine = Engine::new();
let data = ParsedData::from_json(r#"{"user": {"age": 34}}"#).unwrap();
// Evaluate many rules against the one parsed payload.
let adult = engine.compile(r#"{">=": [{"var": "user.age"}, 18]}"#).unwrap();
let senior = engine.compile(r#"{">=": [{"var": "user.age"}, 65]}"#).unwrap();
let arena = Bump::new();
assert_eq!(engine.evaluate(&adult, &data, &arena).unwrap().as_bool(), Some(true));
assert_eq!(engine.evaluate(&senior, &data, &arena).unwrap().as_bool(), Some(false));Implementations§
Source§impl ParsedData
impl ParsedData
Sourcepub fn from_json(json: &str) -> Result<Self>
pub fn from_json(json: &str) -> Result<Self>
Parse json into a self-contained document.
Returns the engine’s usual ParseError on malformed input.
Sourcepub fn value(&self) -> &DataValue<'_>
pub fn value(&self) -> &DataValue<'_>
Borrow the parsed tree.
The returned reference is valid for as long as the handle lives;
it satisfies the &DataValue input shape of the evaluation
entry points directly.
Sourcepub fn allocated_bytes(&self) -> usize
pub fn allocated_bytes(&self) -> usize
Bytes currently held by the backing arena (input copy + tree).
Trait Implementations§
Source§impl Debug for ParsedData
impl Debug for ParsedData
Auto Trait Implementations§
impl !RefUnwindSafe for ParsedData
impl !Sync for ParsedData
impl !UnwindSafe for ParsedData
impl Freeze for ParsedData
impl Send for ParsedData
impl Unpin for ParsedData
impl UnsafeUnpin for ParsedData
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