Skip to main content

DataContext

Struct DataContext 

Source
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 against base_path)
  • Dynamic value resolution (literals, bindings, function calls)

Implementations§

Source§

impl<'a> DataContext<'a>

Source

pub fn new( data_model: &'a DataModel, functions: &'a HashMap<String, Box<dyn FunctionImplementation>>, ) -> Self

Create a new DataContext at the root scope.

Source

pub fn nested(&self, relative_path: &str) -> DataContext<'a>

Create a nested context for template iteration.

Source

pub fn base_path(&self) -> &str

Get the current base path.

Source

pub fn resolve_pointer(&self, path: &str) -> String

Resolve a possibly-relative pointer to an absolute JSON Pointer.

Source

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

Get a value at a (possibly relative) path.

Source

pub fn resolve_dynamic_string(&self, ds: &DynamicString) -> String

Resolve a DynamicString to its current string value.

Source

pub fn resolve_dynamic_number(&self, dn: &DynamicNumber) -> f64

Resolve a DynamicNumber.

Source

pub fn resolve_dynamic_boolean(&self, db: &DynamicBoolean) -> bool

Resolve a DynamicBoolean.

Source

pub fn resolve_dynamic_boolean_condition( &self, db: &DynamicBooleanCondition, ) -> bool

Resolve a DynamicBooleanCondition (same logic as DynamicBoolean).

Source

pub fn resolve_dynamic_value(&self, dv: &DynamicValue) -> Value

Resolve a DynamicValue to a serde_json::Value.

Source

pub fn call_function_by_name( &self, name: &str, args: &HashMap<String, Value>, ) -> Option<Value>

Call a function by name with pre-resolved arguments.

Returns None if the function is not found or execution fails.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for DataContext<'a>

§

impl<'a> !UnwindSafe for DataContext<'a>

§

impl<'a> Freeze for DataContext<'a>

§

impl<'a> Send for DataContext<'a>

§

impl<'a> Sync for DataContext<'a>

§

impl<'a> Unpin for DataContext<'a>

§

impl<'a> UnsafeUnpin for DataContext<'a>

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.