pub struct Context { /* private fields */ }
Expand description
Evaluation context that manages variable scopes and evaluation state
Implementations§
Source§impl Context
impl Context
pub fn new() -> Self
pub fn with_max_depth(max_depth: usize) -> Self
Sourcepub fn check_depth(&self) -> Result<()>
pub fn check_depth(&self) -> Result<()>
Check if we’ve exceeded the maximum depth
Sourcepub fn push_depth(&mut self) -> Result<()>
pub fn push_depth(&mut self) -> Result<()>
Increment evaluation depth
Sourcepub fn get_variable(&self, name: &str) -> Option<&JsonnetValue>
pub fn get_variable(&self, name: &str) -> Option<&JsonnetValue>
Get a variable by name, searching from local to global scope
Sourcepub fn set_variable(&mut self, name: String, value: JsonnetValue)
pub fn set_variable(&mut self, name: String, value: JsonnetValue)
Set a variable in the current scope (local if available, otherwise global)
Sourcepub fn set_global(&mut self, name: String, value: JsonnetValue)
pub fn set_global(&mut self, name: String, value: JsonnetValue)
Set a variable in the global scope specifically
Sourcepub fn has_variable(&self, name: &str) -> bool
pub fn has_variable(&self, name: &str) -> bool
Check if a variable exists in any scope
Sourcepub fn push_scope(&mut self)
pub fn push_scope(&mut self)
Push a new local scope
Sourcepub fn current_scope(&mut self) -> Option<&mut Scope>
pub fn current_scope(&mut self) -> Option<&mut Scope>
Get the current scope (for setting variables)
Sourcepub fn global_scope(&self) -> &Scope
pub fn global_scope(&self) -> &Scope
Get the global scope
Sourcepub fn global_scope_mut(&mut self) -> &mut Scope
pub fn global_scope_mut(&mut self) -> &mut Scope
Get the global scope mutably
Sourcepub fn all_variables(&self) -> HashMap<String, &JsonnetValue>
pub fn all_variables(&self) -> HashMap<String, &JsonnetValue>
Get all variables from all scopes (for debugging)
Sourcepub fn fork(&self) -> Self
pub fn fork(&self) -> Self
Create a new context with the same global scope but empty local scopes
Sourcepub fn merge_locals_to_global(&mut self)
pub fn merge_locals_to_global(&mut self)
Merge local scopes back into global scope (for top-level evaluation)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnwindSafe for Context
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more