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:
- Variable resolution through
get_referencedandset_referenced - Function dispatch through
function_callandmethod_call - Closure parameter management through
start_closure,set_key,set_value, andend_closure - Inference operations through
inference_call
See the Context struct for a complete implementation that supports
workflow-based evaluation with proper scoping and caching.
Required Methods§
Sourcefn start_closure(&mut self) -> [(String, Value); 2]
fn start_closure(&mut self) -> [(String, Value); 2]
Start a new closure and save the current stack.
Sourcefn set_key(&mut self, index: usize, identifier: &str)
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
Sourcefn set_value(&mut self, index: usize, value: &Value)
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
Sourcefn end_closure(&mut self, stack: [(String, Value); 2])
fn end_closure(&mut self, stack: [(String, Value); 2])
End the closure and restore the previous stack.
Sourcefn get_referenced(&mut self, reference: &Reference) -> Result<Value>
fn get_referenced(&mut self, reference: &Reference) -> Result<Value>
Sourcefn method_call(&mut self, name: &str, value: Value, arg: Value) -> Result<Value>
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 callvalue- The value on which to call the methodarg- 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.
Sourcefn inference_call(&mut self, reference: &Reference, arg: Value) -> Result<Value>
fn inference_call(&mut self, reference: &Reference, arg: Value) -> Result<Value>
Run inference on a referenced workflow.
§Arguments
reference- The workflow referencearg- 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.