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
impl Rule
Sourcepub fn new(
identifier: String,
typedef: Typedef,
expression: Expression,
value: Value,
) -> Self
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 identifiertypedef: The type definition for the ruleexpression: The expression that computes the rule’s valuevalue: 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)
Sourcepub fn new_from(
input: &str,
identifier: &str,
typedef: &Typedef,
is_assignment: bool,
) -> Self
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 operandsidentifier: The rule’s identifiertypedef: The rule’s type definitionis_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
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Check if the rule is completely empty (no expression and no value)
Sourcepub fn has_expression(&self) -> bool
pub fn has_expression(&self) -> bool
Check if the rule has a non-empty expression
Sourcepub fn identifier(&self) -> &str
pub fn identifier(&self) -> &str
Get the rule’s identifier
Sourcepub fn ucid(&self) -> String
pub fn ucid(&self) -> String
Get the uppercase identifier (trimming leading underscore if present)
Useful for case-insensitive comparisons and display purposes
Sourcepub fn lcid(&self) -> String
pub fn lcid(&self) -> String
Get the lowercase identifier (trimming leading underscore if present)
Useful for case-insensitive comparisons and display purposes
Sourcepub fn set_identifier(&mut self, identifier: String)
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
Sourcepub fn is_modifier(&self) -> bool
pub fn is_modifier(&self) -> bool
Check if this is a modifier rule (all uppercase identifier)
Sourcepub fn is_assignment(&self) -> bool
pub fn is_assignment(&self) -> bool
Check if this is an assignment rule (identifier starts with underscore)
Sourcepub fn assign(
&mut self,
value: Value,
context: &mut dyn ContextLike,
) -> Result<()>
pub fn assign( &mut self, value: Value, context: &mut dyn ContextLike, ) -> Result<()>
Assign a value to this rule
§Parameters
value: The value to assigncontext: 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
Sourcepub fn set_typedef(&mut self, typedef: Typedef)
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
Sourcepub fn expression(&self) -> &Expression
pub fn expression(&self) -> &Expression
Get the rule’s expression
Sourcepub fn set_expression(&mut self, expression: Expression)
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
Sourcepub fn set_pass(&mut self)
pub fn set_pass(&mut self)
Mark an evaluation rule as passing
Only affects rules with Eval type definitions
Sourcepub fn set_fail(&mut self)
pub fn set_fail(&mut self)
Mark an evaluation rule as failing
Only affects rules with Eval type definitions
Sourcepub fn get_node(&self) -> Option<Node>
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
Sourcepub fn save(&mut self, writer: &mut Writer)
pub fn save(&mut self, writer: &mut Writer)
Save the rule to a writer
Writes the complete rule definition and clears the touched flag
Sourcepub fn partial_save(&mut self, index: usize, writer: &mut Writer)
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 structurewriter: The writer to save to
Trait Implementations§
Source§impl ExpressionLike for Rule
impl ExpressionLike for Rule
Source§fn write(&self, writer: &mut Writer)
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
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
fn to_formula(&self) -> String
Get the rule’s formula representation
Produces a string suitable for formula evaluation
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.