Skip to main content

ParsedData

Struct ParsedData 

Source
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

Source

pub fn from_json(json: &str) -> Result<Self>

Parse json into a self-contained document.

Returns the engine’s usual ParseError on malformed input.

Source

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.

Source

pub fn allocated_bytes(&self) -> usize

Bytes currently held by the backing arena (input copy + tree).

Trait Implementations§

Source§

impl Debug for ParsedData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> EvalInput<'a> for &'a ParsedData

Source§

fn into_arena_value(self, _arena: &'a Bump) -> Result<&'a DataValue<'a>>

Materialise self as a &'a DataValue<'a> in arena. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.