pub struct DataContext<'a> { /* private fields */ }Expand description
A scoped window into the DataModel used during rendering.
Handles:
- Absolute paths (starting with
/) - Relative paths (no leading
/, resolved againstbase_path) - Dynamic value resolution (literals, bindings, function calls)
Implementations§
Source§impl<'a> DataContext<'a>
impl<'a> DataContext<'a>
Sourcepub fn new(
data_model: &'a DataModel,
functions: &'a HashMap<String, Box<dyn FunctionImplementation>>,
) -> Self
pub fn new( data_model: &'a DataModel, functions: &'a HashMap<String, Box<dyn FunctionImplementation>>, ) -> Self
Create a new DataContext at the root scope.
Sourcepub fn nested(&self, relative_path: &str) -> DataContext<'a>
pub fn nested(&self, relative_path: &str) -> DataContext<'a>
Create a nested context for template iteration.
The nested context starts with no template index; callers that need the
@index system function (e.g. when expanding a ChildList::Template)
set it via with_template_index.
Sourcepub fn template_index(&self) -> Option<usize>
pub fn template_index(&self) -> Option<usize>
Return the template index for this context, if any.
Sourcepub fn with_template_index(self, index: Option<usize>) -> Self
pub fn with_template_index(self, index: Option<usize>) -> Self
Set the template index (builder style). Returns self for chaining.
Some(i) enables the @index system function for this context;
None disables it.
Sourcepub fn set_template_index(&mut self, index: Option<usize>)
pub fn set_template_index(&mut self, index: Option<usize>)
Set the template index in place.
Sourcepub fn resolve_pointer(&self, path: &str) -> String
pub fn resolve_pointer(&self, path: &str) -> String
Resolve a possibly-relative pointer to an absolute JSON Pointer.
Sourcepub fn resolve_dynamic_string(&self, ds: &DynamicString) -> String
pub fn resolve_dynamic_string(&self, ds: &DynamicString) -> String
Resolve a DynamicString to its current string value.
Sourcepub fn resolve_dynamic_number(&self, dn: &DynamicNumber) -> f64
pub fn resolve_dynamic_number(&self, dn: &DynamicNumber) -> f64
Resolve a DynamicNumber.
Sourcepub fn resolve_dynamic_boolean(&self, db: &DynamicBoolean) -> bool
pub fn resolve_dynamic_boolean(&self, db: &DynamicBoolean) -> bool
Resolve a DynamicBoolean.
Sourcepub fn resolve_dynamic_boolean_condition(
&self,
db: &DynamicBooleanCondition,
) -> bool
pub fn resolve_dynamic_boolean_condition( &self, db: &DynamicBooleanCondition, ) -> bool
Resolve a DynamicBooleanCondition (same logic as DynamicBoolean).
Sourcepub fn resolve_dynamic_value(&self, dv: &DynamicValue) -> Value
pub fn resolve_dynamic_value(&self, dv: &DynamicValue) -> Value
Resolve a DynamicValue to a serde_json::Value.