pub struct Context { /* private fields */ }Expand description
Default AIMX evaluation context implementing ContextLike.
Holds the current locator, active workflow (read-only and optional mutable clone), closure parameters, and an optional workflow lock. Supports reference resolution, rule updates, inference into nested workflows, and imperative workflow execution. Not thread-safe; use per evaluation.
Implementations§
Source§impl Context
impl Context
pub fn for_testing() -> Result<Self>
Sourcepub fn with_value(self, identifier: &str, value: Value) -> Self
pub fn with_value(self, identifier: &str, value: Value) -> Self
Test Helper function to add a predefined value to the context for testing purposes.
This method creates a rule with the given identifier and value and adds it to the workspace. This is primarily used for testing expressions that reference predefined variables.
§Arguments
identifier- The identifier name for the valuevalue- The value to associate with the identifier
§Returns
Returns the modified context for method chaining.
Sourcepub fn with_rule(
self,
identifier: &str,
typedef: Typedef,
expression: Expression,
value: Value,
) -> Self
pub fn with_rule( self, identifier: &str, typedef: Typedef, expression: Expression, value: Value, ) -> Self
Test Helper function to add a predefined rule to the context for testing purposes.
Sourcepub fn with_commit(self) -> Self
pub fn with_commit(self) -> Self
Test Helper function to commit the predefined rules to the source workflow for testing.
Sourcepub fn get_local(&mut self, identifier: &str) -> Result<Arc<Value>>
pub fn get_local(&mut self, identifier: &str) -> Result<Arc<Value>>
Test Helper function to lookup the predefined rule values in the workflow for testing.
pub fn open( source_locator: Arc<Reference>, target_locator: Arc<Reference>, ) -> Result<Self>
pub fn save(&mut self) -> Result<()>
pub fn save_all(&mut self) -> Result<()>
Sourcepub fn source(&self) -> Arc<Workflow>
pub fn source(&self) -> Arc<Workflow>
Gets read-only access to the current workflow.
Returns a clone of the Arc reference to the current workflow, allowing read-only access to workflow data without affecting the context’s ownership.
Sourcepub fn target(&mut self) -> &mut Workflow
pub fn target(&mut self) -> &mut Workflow
Gets mutable access to the workflow if available.
Returns a mutable reference to the workflow if one is currently being modified, or None if only read-only access is available.
pub fn print(&self, writer: &mut Writer)
Trait Implementations§
Source§impl ContextLike for Context
impl ContextLike for Context
Source§fn start_closure(&mut self) -> [(Arc<str>, Arc<Value>); 2]
fn start_closure(&mut self) -> [(Arc<str>, Arc<Value>); 2]
Start a new closure and save the current parameter stack.
Source§fn set_key(&mut self, index: usize, identifier: Arc<str>)
fn set_key(&mut self, index: usize, identifier: Arc<str>)
Set the key of the indexed mapped parameter 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_parameter(&mut self, index: usize, value: Arc<Value>)
fn set_parameter(&mut self, index: usize, value: Arc<Value>)
Set the value of the index mapped parameter 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: [(Arc<str>, Arc<Value>); 2])
fn end_closure(&mut self, stack: [(Arc<str>, Arc<Value>); 2])
End the closure and restore the previous parameter stack.
Source§fn get_value(&mut self, reference: &Reference) -> Result<Arc<Value>>
fn get_value(&mut self, reference: &Reference) -> Result<Arc<Value>>
Get the value of a referenced rule or parameter variable.
This implementation only supports single-part references (default identifiers).
Multi-part references (e.g., object.property) are not supported in this
simplified context.
§Arguments
reference- The reference to resolve
§Returns
Returns a Result<Value> containing the referenced value or an error
if the reference cannot be resolved.
Source§fn function_call(
&mut self,
name: Arc<str>,
arg: Arc<Value>,
) -> Result<Arc<Value>>
fn function_call( &mut self, name: Arc<str>, arg: Arc<Value>, ) -> Result<Arc<Value>>
Call a standalone function.
Delegates function calls to the singleton function registry.
§Arguments
name- The name of the function to callarg- The argument(s) to pass to the function
§Returns
Returns a Result<Value> containing the function result or an error
if the function is not found or execution fails.
Source§fn method_call(
&mut self,
name: Arc<str>,
value: Arc<Value>,
arg: Arc<Value>,
) -> Result<Arc<Value>>
fn method_call( &mut self, name: Arc<str>, value: Arc<Value>, arg: Arc<Value>, ) -> Result<Arc<Value>>
Call a method on a value.
Delegates method calls to the singleton function registry.
§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
§Returns
Returns a Result<Value> containing the method result or an error
if the method is not found or execution fails.
Source§fn inference_call(
&mut self,
reference: Arc<Reference>,
arg: Arc<Value>,
) -> Result<Arc<Value>>
fn inference_call( &mut self, reference: Arc<Reference>, arg: Arc<Value>, ) -> Result<Arc<Value>>
Run inference on a workflow node or call a closure.
Node- Delegates inference to a workflow nodeClosure- Delegates closure calls to a first class function
§Arguments
reference- A reference to the rule containing the node or closurearg- The argument(s) to pass to the inference/call
§Returns
Returns a Result<Value> containing the inference/call result or an error
if the rule is not found or the inference/call fails.
Source§fn run_evaluation(&mut self, start_state: Option<Arc<str>>) -> WorkflowStatus
fn run_evaluation(&mut self, start_state: Option<Arc<str>>) -> WorkflowStatus
Evaluate this workflow as an imperative rule program.
This interpreter walks rules by row index and respects control-flow values produced by rule evaluation.
Branch and Retry rules are treated as workflow-level control
constructs; their Value::Branch results are not written back
via set_value.
To guard against accidental cycles (e.g. infinite branch loops),
a fixed maximum step count is enforced. Exceeding this limit
terminates evaluation with a WorkflowStatus::Failed result.
§Parameters
context- The evaluation context providing variable accessstart_state- Optional rule identifier to start from when resuming a suspended workflow.