Struct Rule

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

A single rule in an AIM structure representing a workflow component

Rules are the fundamental building blocks of AIM workflows, defining how values are computed, formatted, evaluated, or assigned. Each rule consists of:

  • An identifier that uniquely names the rule
  • A type definition that constrains valid values
  • An expression that computes the rule’s value
  • A current value (computed or assigned)
  • Internal flags tracking state and category

§Examples

// Create a simple rule
let rule = Rule::new(
    "temperature".to_string(),
    Typedef::Number,
    Expression::Empty,
    Value::Literal(Literal::from_number(25.0))
);

Implementations§

Source§

impl Rule

Source

pub fn new( identifier: String, typedef: Typedef, expression: Expression, value: Value, ) -> Self

Create a new Rule with the given components

§Parameters
  • identifier: The rule’s unique identifier
  • typedef: The type definition for the rule
  • expression: The expression that computes the rule’s value
  • value: The initial value of the rule
§Returns

A new Rule instance with appropriate flags set based on the identifier

§Notes
  • Automatically performs static evaluation of expressions when possible
  • Sets flags based on identifier format (modifier/assignment)
Source

pub fn new_from( input: &str, identifier: &str, typedef: &Typedef, is_assignment: bool, ) -> Self

Create a new Rule by parsing operands from a string

This constructor parses the expression/value portion of a rule definition based on the rule’s type definition and assignment status.

§Parameters
  • input: The string containing the rule’s operands
  • identifier: The rule’s identifier
  • typedef: The rule’s type definition
  • is_assignment: Whether this is an assignment rule
§Returns

A new Rule instance with parsed expression and value

§Errors

Returns error expressions for incomplete or malformed input

Source

pub fn is_empty(&self) -> bool

Check if the rule is completely empty (no expression and no value)

Source

pub fn has_error(&self) -> bool

Check if the rule contains any errors

Source

pub fn has_expression(&self) -> bool

Check if the rule has a non-empty expression

Source

pub fn identifier(&self) -> &str

Get the rule’s identifier

Source

pub fn ucid(&self) -> String

Get the uppercase identifier (trimming leading underscore if present)

Useful for case-insensitive comparisons and display purposes

Source

pub fn lcid(&self) -> String

Get the lowercase identifier (trimming leading underscore if present)

Useful for case-insensitive comparisons and display purposes

Source

pub fn set_identifier(&mut self, identifier: String)

Set a new identifier for the rule

Updates the identifier and automatically adjusts flags based on the new identifier format

Source

pub fn is_modifier(&self) -> bool

Check if this is a modifier rule (all uppercase identifier)

Source

pub fn is_assignment(&self) -> bool

Check if this is an assignment rule (identifier starts with underscore)

Source

pub fn assign( &mut self, value: Value, context: &mut dyn ContextLike, ) -> Result<()>

Assign a value to this rule

§Parameters
  • value: The value to assign
  • context: The evaluation context for resolving references
§Returns

Ok(()) if assignment was successful, Err if type mismatch occurs

§Notes
  • For assignment rules, sets the referenced value in the context
  • For other rules, directly sets the rule’s value
Source

pub fn typedef(&self) -> &Typedef

Get the rule’s type definition

Source

pub fn set_typedef(&mut self, typedef: Typedef)

Set a new type definition for the rule

Resets the value to empty and marks the rule as touched

Source

pub fn expression(&self) -> &Expression

Get the rule’s expression

Source

pub fn set_expression(&mut self, expression: Expression)

Set a new expression for the rule

Marks the rule as touched if the expression differs from the current one

Source

pub fn value(&self) -> &Value

Get the rule’s current value

Source

pub fn set_value(&mut self, value: Value) -> Result<()>

Set the rule’s value

§Parameters
  • value: The value to set
§Returns

Ok(()) if the value matches the rule’s type, Err otherwise

Source

pub fn is_format(&self) -> bool

Check if this is a format rule

Source

pub fn is_eval(&self) -> bool

Check if this is an evaluation rule

Source

pub fn set_pass(&mut self)

Mark an evaluation rule as passing

Only affects rules with Eval type definitions

Source

pub fn set_fail(&mut self)

Mark an evaluation rule as failing

Only affects rules with Eval type definitions

Source

pub fn is_node(&self) -> bool

Check if this is a node rule

Source

pub fn get_node(&self) -> Option<Node>

Get the node from this rule if it is a node rule

§Returns

Some(Node) if this is a node rule with a node value, None otherwise

Source

pub fn touch(&mut self)

Mark the rule as touched (modified and needing saving)

Source

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

Save the rule to a writer

Writes the complete rule definition and clears the touched flag

Source

pub fn partial_save(&mut self, index: usize, writer: &mut Writer)

Perform a partial save of the rule

Only saves if the rule has been touched, prepending the rule index

§Parameters
  • index: The index of this rule in its parent structure
  • writer: The writer to save to

Trait Implementations§

Source§

impl Clone for Rule

Source§

fn clone(&self) -> Rule

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Rule

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for Rule

Source§

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

Display the rule’s content (expression or value) for user-facing output

Source§

impl ExpressionLike for Rule

Source§

fn evaluate(&self, context: &mut dyn ContextLike) -> Result<Value>

Evaluate the rule’s expression or value in the given context

If the rule has an expression, evaluates it. Otherwise, evaluates the rule’s value.

§Parameters
  • context: The evaluation context
§Returns

Ok(Value) containing the evaluated result

Source§

fn write(&self, writer: &mut Writer)

Write the rule’s complete definition to a writer

Outputs the rule in AIM format: identifier: typedef = expression @ value

Source§

fn to_sanitized(&self) -> String

Get a sanitized string representation of the rule

Removes sensitive information and produces a safe representation

Source§

fn to_formula(&self) -> String

Get the rule’s formula representation

Produces a string suitable for formula evaluation

Source§

impl PartialEq for Rule

Source§

fn eq(&self, other: &Rule) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Rule

Auto Trait Implementations§

§

impl Freeze for Rule

§

impl RefUnwindSafe for Rule

§

impl Send for Rule

§

impl Sync for Rule

§

impl Unpin for Rule

§

impl UnwindSafe for Rule

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

impl<T> ToStringFallible for T
where T: Display,

§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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,