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
impl EvalData
Sourcepub fn with_schema_data_context(
evaluated_schema: &Value,
input_data: &Value,
context_data: &Value,
) -> Self
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
Sourcepub fn replace_data_and_context(
&mut self,
input_data: Value,
context_data: Value,
)
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
Sourcepub fn instance_id(&self) -> u64
pub fn instance_id(&self) -> u64
Get the unique instance ID
Sourcepub fn data(&self) -> &Value
pub fn data(&self) -> &Value
Get a reference to the underlying data (read-only) Zero-cost access via Arc dereference
Sourcepub fn clone_data_without(&self, exclude: &[&str]) -> Value
pub fn clone_data_without(&self, exclude: &[&str]) -> Value
Clone a Value without certain keys
Sourcepub fn set(&mut self, path: &str, value: Value)
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
Sourcepub fn push_to_array(&mut self, path: &str, value: Value)
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
Sourcepub fn get(&self, path: &str) -> Option<&Value>
pub fn get(&self, path: &str) -> Option<&Value>
Get a field value Accepts both dotted notation (user.name) and JSON pointer format (/user/name)
pub fn get_without_properties(&self, path: &str) -> Option<&Value>
Sourcepub fn get_array_element(
&self,
array_path: &str,
index: usize,
) -> Option<&Value>
pub fn get_array_element( &self, array_path: &str, index: usize, ) -> Option<&Value>
OPTIMIZED: Fast array element access
Sourcepub fn get_mut(&mut self, path: &str) -> Option<&mut Value>
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
Sourcepub fn get_table_row_mut(
&mut self,
path: &str,
index: usize,
) -> Option<&mut Map<String, Value>>
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