Trait ContextLike

Source
pub trait ContextLike {
    // Required methods
    fn start_closure(&mut self) -> [(String, Value); 2];
    fn set_key(&mut self, index: usize, identifier: &str);
    fn set_value(&mut self, index: usize, value: &Value);
    fn end_closure(&mut self, stack: [(String, Value); 2]);
    fn get_referenced(&mut self, reference: &Reference) -> Result<Value>;
    fn set_referenced(
        &mut self,
        reference: &Reference,
        value: Value,
    ) -> Result<()>;
    fn function_call(&mut self, name: &str, arg: Value) -> Result<Value>;
    fn method_call(
        &mut self,
        name: &str,
        value: Value,
        arg: Value,
    ) -> Result<Value>;
    fn inference_call(
        &mut self,
        reference: &Reference,
        arg: Value,
    ) -> Result<Value>;
}
Expand description

Trait for evaluation contexts that provide runtime environment for expression evaluation.

This trait defines the interface that evaluation contexts must implement. A context provides variable values, handles function calls, manages closure parameters, and provides the runtime environment for expression evaluation.

The ContextLike trait is designed to be implemented by context types that need to:

  • Resolve variable references during evaluation
  • Handle function and method calls
  • Manage closure parameters for functional programming constructs
  • Support inference operations for agentic workflows

§Implementation Requirements

Implementors must manage:

See the Context struct for a complete implementation that supports workflow-based evaluation with proper scoping and caching.

Required Methods§

Source

fn start_closure(&mut self) -> [(String, Value); 2]

Start a new closure and save the current stack.

Source

fn set_key(&mut self, index: usize, identifier: &str)

Set the key of the indexed mapped variable used by element-wise functions like map.

§Arguments
  • index - The index key to set (0 or 1)
  • identifier - The key to set
Source

fn set_value(&mut self, index: usize, value: &Value)

Set the value of the index mapped variable used by element-wise functions like map.

§Arguments
  • index - The index value to set (0 or 1)
  • value - The value to set
Source

fn end_closure(&mut self, stack: [(String, Value); 2])

End the closure and restore the previous stack.

Source

fn get_referenced(&mut self, reference: &Reference) -> Result<Value>

Get the value of a referenced variable or expression.

§Arguments
  • reference - The reference to resolve
§Returns

Returns the value of the referenced variable or an error if the reference cannot be resolved.

Source

fn set_referenced(&mut self, reference: &Reference, value: Value) -> Result<()>

Set the value of a referenced variable.

§Arguments
  • reference - The reference to set
  • value - The value to assign
§Returns

Returns Ok(()) on success or an error if the referenced variable cannot be set.

Source

fn function_call(&mut self, name: &str, arg: Value) -> Result<Value>

Call a standalone function.

§Arguments
  • name - The name of the function to call
  • arg - The argument(s) to pass to the function (Value can be Empty, Literal, or Array)
§Returns

Returns the result of the function call or an error if the function is not found or if there’s an error during execution.

Source

fn method_call(&mut self, name: &str, value: Value, arg: Value) -> Result<Value>

Call a method on a value.

§Arguments
  • name - The name of the method to call
  • value - The value on which to call the method
  • arg - The argument(s) to pass to the method (Value can be Empty, Literal, or Array)
§Returns

Returns the result of the method call or an error if the method is not found or if there’s an error during execution.

Source

fn inference_call(&mut self, reference: &Reference, arg: Value) -> Result<Value>

Run inference on a referenced workflow.

§Arguments
  • reference - The workflow reference
  • arg - The argument(s) to pass to the inference call (Value can be Empty, Literal, or Array)
§Returns

Returns the result of the inference call or an error if the workflow is not found or if there’s an error during execution.

Implementors§