pub struct Rule { /* private fields */ }Expand description
Single AIM rule: identifier, typedef, expression, and value.
Constructors perform identifier-based classification and optional
static folding of constant expressions into value.
Implementations§
Source§impl Rule
impl Rule
Sourcepub fn new(
identifier: Arc<str>,
typedef: Typedef,
expression: Expression,
value: Arc<Value>,
) -> Self
pub fn new( identifier: Arc<str>, typedef: Typedef, expression: Expression, value: Arc<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)
pub fn convert( identifier: Arc<str>, typedef: Arc<str>, formula: Arc<str>, value: Arc<str>, ) -> Self
Sourcepub fn parse(&self, input: &str) -> Self
pub fn parse(&self, input: &str) -> 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) -> Arc<str>
pub fn identifier(&self) -> Arc<str>
Get the rule’s identifier
Sourcepub fn ucid(&self) -> Arc<str>
pub fn ucid(&self) -> Arc<str>
Get the uppercase form of the identifier.
Non-alphabetic characters (such as _ or digits) are preserved; only
alphabetic characters are converted to uppercase.
Sourcepub fn lcid(&self) -> Arc<str>
pub fn lcid(&self) -> Arc<str>
Get the lowercase form of the identifier.
Non-alphabetic characters (such as _ or digits) are preserved; only
alphabetic characters are converted to lowercase.
Sourcepub fn set_identifier(&mut self, identifier: Arc<str>) -> bool
pub fn set_identifier(&mut self, identifier: Arc<str>) -> bool
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 set_typedef(&mut self, typedef: Typedef) -> bool
pub fn set_typedef(&mut self, typedef: Typedef) -> bool
Set a new type definition for the rule
Resets the value to empty and marks the rule as touched
§Returns
true if the rule changed, else false
Sourcepub fn expression(&self) -> &Expression
pub fn expression(&self) -> &Expression
Get the rule’s expression
Sourcepub fn set_expression(&mut self, expression: Expression) -> bool
pub fn set_expression(&mut self, expression: Expression) -> bool
Set a new expression for the rule
Marks the rule as touched if the expression differs from the current one
§Returns
true if the rule changed, else false
pub fn rename_node(&self, identifier: Arc<str>) -> Result<Self>
Sourcepub fn set_pass(&mut self) -> Result<()>
pub fn set_pass(&mut self) -> Result<()>
Mark an evaluation rule as passing
Only affects rules with Eval type definitions
§Returns
true if the rule changed, else false
Sourcepub fn set_fail(&mut self) -> Result<()>
pub fn set_fail(&mut self) -> Result<()>
Mark an evaluation rule as failing
Only affects rules with Eval type definitions
§Returns
true if the rule changed, else false
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
pub fn get_instance(&self) -> Option<Instance>
Trait Implementations§
Source§impl ExpressionLike for Rule
impl ExpressionLike for Rule
Source§fn evaluate(&self, context: &mut dyn ContextLike) -> Result<Arc<Value>>
fn evaluate(&self, context: &mut dyn ContextLike) -> Result<Arc<Value>>
Evaluate the rule’s expression and return a Value, handling errors
gracefully, or if empty, return the rule’s value.
- If
expressionis non-empty, this evaluates the expression. - If
expressionis empty, this returns a clone of the storedvalue.
This method evaluates the rule expression in the given context.
- If the expression is empty, returns the stored value.
- If the expression is non-empty, delegates to the underlying
ExpressionLike::evaluateimplementation.
§Arguments
context- The evaluation context providing variable values and function implementations
§Returns
Returns a Value representing the result of evaluation. If evaluation
succeeds, returns the computed value. If evaluation fails, returns an
Errata value containing error information.
§See Also
ExpressionLike::evaluate- The underlying evaluation method that returnsResultValue- The result type returned by evaluation
Source§fn to_formula(&self) -> String
fn to_formula(&self) -> String
Return the formula-string representation (round-trippable by the parser).
Source§impl WriterLike for Rule
impl WriterLike for Rule
Source§fn to_stringized(&self) -> String
fn to_stringized(&self) -> String
Source§fn to_sanitized(&self) -> String
fn to_sanitized(&self) -> String
Source§fn to_expressionized(&self) -> String
fn to_expressionized(&self) -> String
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.