Rule

Struct Rule 

Source
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

Source

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 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 convert( identifier: Arc<str>, typedef: Arc<str>, formula: Arc<str>, value: Arc<str>, ) -> Self

Source

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 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 is_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) -> Arc<str>

Get the rule’s identifier

Source

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.

Source

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.

Source

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

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 typedef(&self) -> &Typedef

Get the rule’s type definition

Source

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

Source

pub fn expression(&self) -> &Expression

Get the rule’s expression

Source

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

Source

pub fn value(&self) -> Arc<Value>

Get the rule’s current value

Source

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

Set the rule’s value

§Parameters

The value to set. Must match typedef unless empty or error.

This function does not set special typedef values.

§Returns

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

Source

pub fn rename_node(&self, identifier: Arc<str>) -> Result<Self>

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

Mark an evaluation rule as passing

Only affects rules with Eval type definitions

§Returns

true if the rule changed, else false

Source

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

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 get_instance(&self) -> Option<Instance>

Source

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

Write the rule’s complete definition to a writer

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

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<Arc<Value>>

Evaluate the rule’s expression and return a Value, handling errors gracefully, or if empty, return the rule’s value.

  • If expression is non-empty, this evaluates the expression.
  • If expression is empty, this returns a clone of the stored value.

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::evaluate implementation.
§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
Source§

fn to_formula(&self) -> String

Return the formula-string representation (round-trippable by the parser).

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 WriterLike for Rule

Source§

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

Serialize this expression with the given Writer.
Source§

fn to_stringized(&self) -> String

Return a string representation (raw unsafe output).
Source§

fn to_sanitized(&self) -> String

Return a sanitized string representation (escaped for safe output).
Source§

fn to_expressionized(&self) -> String

Return a sanitized string representation (escaped for safe output).
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,