ContextStack

Struct ContextStack 

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

Context stack for nested evaluations

Implementations§

Source§

impl ContextStack

Source

pub fn new(root: Arc<Value>) -> Self

Create a new context stack with Arc root data

Source

pub fn push(&mut self, data: Value)

Pushes a new context frame for nested evaluation.

Used by operators that need to create a nested data context without metadata.

§Arguments
  • data - The data value for the new context frame
Source

pub fn push_with_metadata( &mut self, data: Value, metadata: HashMap<String, Value>, )

Pushes a frame with metadata for iteration operations.

Used by array operators like map, filter, and reduce to provide iteration context including index and key information.

§Arguments
  • data - The current item being processed
  • metadata - Iteration metadata (typically includes “index” and optionally “key”)
§Example

During array iteration:

let mut metadata = HashMap::new();
metadata.insert("index".to_string(), json!(0));
context.push_with_metadata(item_value, metadata);
Source

pub fn pop(&mut self) -> Option<ContextFrame>

Pops the current context frame from the stack.

Restores the previous context after nested evaluation completes. Returns None if there are no frames to pop (root is never popped).

§Returns

The popped context frame, or None if the stack is empty.

Source

pub fn get_at_level(&self, level: isize) -> Option<ContextFrameRef<'_>>

Accesses data at a context level relative to current.

This method enables access to parent contexts during nested operations, which is essential for complex JSONLogic expressions.

§Arguments
  • level - The number of levels to traverse up the context stack
    • 0: returns the current context
    • N (positive or negative): goes up N levels from current
§Returns

A reference to the context frame at the specified level, or None if the level exceeds the stack depth.

§Note

The sign of the level is ignored; both positive and negative values traverse up the stack the same way. This maintains backward compatibility with existing usage patterns.

§Returns

The context frame at the specified level, or the root if level exceeds stack depth

Source

pub fn current(&self) -> ContextFrameRef<'_>

Get the current context frame (top of stack) Returns a temporary frame for root if no frames are pushed

Source

pub fn root(&self) -> ContextFrameRef<'_>

Get the root context frame

Source

pub fn depth(&self) -> usize

Get the current depth (number of frames)

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, 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.