EvalData

Struct EvalData 

Source
pub struct EvalData { /* private fields */ }
Expand description

Tracked data wrapper that gates all mutations for safety

§Design Philosophy

EvalData serves as the single gatekeeper for all data mutations in the system. All write operations (set, push_to_array, get_mut, etc.) MUST go through this type to ensure proper version tracking and mutation safety.

This design provides:

  • Thread-safe mutation tracking via version numbers
  • Copy-on-Write (CoW) semantics via Arc for efficient cloning
  • Single point of control for all data state changes
  • Prevention of untracked mutations that could cause race conditions

§CoW Behavior

  • Read operations are zero-cost (direct Arc dereference)
  • Clone operations are cheap (Arc reference counting)
  • First mutation triggers deep clone via Arc::make_mut
  • Subsequent mutations on exclusive owner are zero-cost

Implementations§

Source§

impl EvalData

Source

pub fn new(data: Value) -> Self

Create a new tracked data wrapper

Source

pub fn with_schema_data_context( evaluated_schema: &Value, input_data: &Value, context_data: &Value, ) -> Self

Initialize eval data with zero-copy references to evaluated_schema, input_data, and context_data This avoids cloning by directly constructing the data structure with borrowed references

Source

pub fn replace_data_and_context( &mut self, input_data: Value, context_data: Value, )

Replace data and context in existing EvalData (for evaluation updates) Uses CoW: replaces Arc, no clone needed if not shared

Source

pub fn instance_id(&self) -> u64

Get the unique instance ID

Source

pub fn data(&self) -> &Value

Get a reference to the underlying data (read-only) Zero-cost access via Arc dereference

Source

pub fn clone_data_without(&self, exclude: &[&str]) -> Value

Clone a Value without certain keys

Source

pub fn set(&mut self, path: &str, value: Value)

Set a field value and increment version Accepts both dotted notation (user.name) and JSON pointer format (/user/name) Uses CoW: clones data only if shared

Source

pub fn push_to_array(&mut self, path: &str, value: Value)

Append to an array field without full clone (optimized for table building) Accepts both dotted notation (items) and JSON pointer format (/items) Uses CoW: clones data only if shared

Source

pub fn get(&self, path: &str) -> Option<&Value>

Get a field value Accepts both dotted notation (user.name) and JSON pointer format (/user/name)

Source

pub fn get_without_properties(&self, path: &str) -> Option<&Value>

Source

pub fn get_array_element( &self, array_path: &str, index: usize, ) -> Option<&Value>

OPTIMIZED: Fast array element access

Source

pub fn get_mut(&mut self, path: &str) -> Option<&mut Value>

Get a mutable reference to a field value Accepts both dotted notation and JSON pointer format Uses CoW: clones data only if shared Note: Caller must manually increment version after mutation

Source

pub fn get_table_row_mut( &mut self, path: &str, index: usize, ) -> Option<&mut Map<String, Value>>

Get a mutable reference to a table row object at path[index] Accepts both dotted notation and JSON pointer format Uses CoW: clones data only if shared Returns None if path is not an array or row is not an object

Source

pub fn get_values<'a>(&'a self, paths: &'a [String]) -> Vec<Cow<'a, Value>>

Get multiple field values efficiently (for cache key generation) OPTIMIZED: Use batch pointer resolution for better performance

Trait Implementations§

Source§

impl Clone for EvalData

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl From<Value> for EvalData

Source§

fn from(value: Value) -> Self

Converts to this type from the input type.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.