Context

Struct Context 

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

Evaluation context that manages variable scopes and evaluation state

Implementations§

Source§

impl Context

Source

pub fn new() -> Self

Source

pub fn with_max_depth(max_depth: usize) -> Self

Source

pub fn depth(&self) -> usize

Get the current evaluation depth

Source

pub fn check_depth(&self) -> Result<()>

Check if we’ve exceeded the maximum depth

Source

pub fn push_depth(&mut self) -> Result<()>

Increment evaluation depth

Source

pub fn pop_depth(&mut self)

Decrement evaluation depth

Source

pub fn get_variable(&self, name: &str) -> Option<&JsonnetValue>

Get a variable by name, searching from local to global scope

Source

pub fn set_variable(&mut self, name: String, value: JsonnetValue)

Set a variable in the current scope (local if available, otherwise global)

Source

pub fn set_global(&mut self, name: String, value: JsonnetValue)

Set a variable in the global scope specifically

Source

pub fn has_variable(&self, name: &str) -> bool

Check if a variable exists in any scope

Source

pub fn push_scope(&mut self)

Push a new local scope

Source

pub fn pop_scope(&mut self) -> Option<Scope>

Pop the current local scope

Source

pub fn current_scope(&mut self) -> Option<&mut Scope>

Get the current scope (for setting variables)

Source

pub fn global_scope(&self) -> &Scope

Get the global scope

Source

pub fn global_scope_mut(&mut self) -> &mut Scope

Get the global scope mutably

Source

pub fn all_variables(&self) -> HashMap<String, &JsonnetValue>

Get all variables from all scopes (for debugging)

Source

pub fn fork(&self) -> Self

Create a new context with the same global scope but empty local scopes

Source

pub fn merge_locals_to_global(&mut self)

Merge local scopes back into global scope (for top-level evaluation)

Trait Implementations§

Source§

impl Debug for Context

Source§

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

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

impl Default for Context

Source§

fn default() -> Self

Returns the “default value” for a type. 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> Same for T

Source§

type Output = T

Should always be Self
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.