Context

Struct Context 

Source
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

Source

pub fn open_with_error_handling( source_locator: Arc<Reference>, target_locator: Arc<Reference>, ) -> Result<Self>

Acquire context with enhanced error handling

Source§

impl Context

Source

pub fn for_testing() -> Result<Self>

Source

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 value
  • value - The value to associate with the identifier
§Returns

Returns the modified context for method chaining.

Source

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.

Source

pub fn with_commit(self) -> Self

Test Helper function to commit the predefined rules to the source workflow for testing.

Source

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.

Source

pub fn open( source_locator: Arc<Reference>, target_locator: Arc<Reference>, ) -> Result<Self>

Source

pub fn save(&mut self) -> Result<()>

Source

pub fn save_all(&mut self) -> Result<()>

Source

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.

Source

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.

Source

pub fn print(&self, writer: &mut Writer)

Trait Implementations§

Source§

impl ContextLike for Context

Source§

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>)

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>)

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])

End the closure and restore the previous parameter stack.

Source§

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 set_value(&mut self, identifier: &str, value: Arc<Value>) -> Result<()>

Get the value of a rule or parameter.

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

Returns Ok(()) if the referenced value was set or an error if the reference cannot be resolved.

Source§

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 call
  • arg - 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>>

Call a method on a value.

Delegates method calls to the singleton function registry.

§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
§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>>

Run inference on a workflow node or call a closure.

  • Node - Delegates inference to a workflow node
  • Closure - Delegates closure calls to a first class function
§Arguments
  • reference - A reference to the rule containing the node or closure
  • arg - 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

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 access
  • start_state - Optional rule identifier to start from when resuming a suspended workflow.
Source§

impl Debug for Context

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,