pub enum Relational {
Less(Additive, Additive),
LessOrEqual(Additive, Additive),
Greater(Additive, Additive),
GreaterOrEqual(Additive, Additive),
Primary(Box<Primary>),
}Expand description
Represents a relational expression in the AIMX grammar.
Relational expressions perform comparisons between values using operators like less than, greater than, less than or equal, and greater than or equal. These expressions form part of the expression hierarchy and can be used in conditional statements and boolean logic.
The Relational enum uses AST flattening optimization, where it includes
variants for lower-precedence expressions. This allows efficient evaluation
without deep recursion.
§Variants
§Comparison Variants
Less- Less than comparison:left < rightLessOrEqual- Less than or equal comparison:left <= rightGreater- Greater than comparison:left > rightGreaterOrEqual- Greater than or equal comparison:left >= right
§AST Flattening Variants
Primary- Flattened primary expression (optimization)
§Examples
use aimx::expressions::relational::{Relational, parse_relational};
use aimx::{ExpressionLike, Context, Value};
// Parse and evaluate a relational expression
let (_, expr) = parse_relational("5 < 10").unwrap();
let mut context = Context::new();
let result = expr.evaluate(&mut context).unwrap();
assert_eq!(result.to_string(), "true");Variants§
Less(Additive, Additive)
Less than comparison: left < right
LessOrEqual(Additive, Additive)
Less than or equal comparison: left <= right
Greater(Additive, Additive)
Greater than comparison: left > right
GreaterOrEqual(Additive, Additive)
Greater than or equal comparison: left >= right
Primary(Box<Primary>)
Primary flattened AST optimization
Trait Implementations§
Source§impl Clone for Relational
impl Clone for Relational
Source§fn clone(&self) -> Relational
fn clone(&self) -> Relational
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Relational
impl Debug for Relational
Source§impl Display for Relational
impl Display for Relational
Source§impl ExpressionLike for Relational
impl ExpressionLike for Relational
Source§fn evaluate(&self, context: &mut dyn ContextLike) -> Result<Value>
fn evaluate(&self, context: &mut dyn ContextLike) -> Result<Value>
Evaluates the relational expression within the given context.
This method performs type-safe comparisons between the left and right operands of the relational expression. It uses type promotion to ensure compatible comparisons and returns a boolean result.
§Type Promotion Rules
The evaluation uses evaluate_and_promote to ensure both operands are
of comparable types. Supported type comparisons include:
- Numbers: Standard numeric comparison
- Booleans:
false(0) <true(1) - Dates: Chronological order comparison
- Text: Lexicographical comparison
- Tasks: Status-based comparison (converted to numbers)
§Errors
Returns an error if:
- The operands are not of comparable types
- Type promotion fails
- Evaluation of sub-expressions fails
§Examples
use aimx::expressions::relational::{Relational, parse_relational};
use aimx::{ExpressionLike, Context};
let (_, expr) = parse_relational("5 < 10").unwrap();
let mut context = Context::new();
let result = expr.evaluate(&mut context).unwrap();
assert_eq!(result.to_string(), "true");Source§fn to_sanitized(&self) -> String
fn to_sanitized(&self) -> String
Source§fn to_formula(&self) -> String
fn to_formula(&self) -> String
Source§impl PartialEq for Relational
impl PartialEq for Relational
impl StructuralPartialEq for Relational
Auto Trait Implementations§
impl Freeze for Relational
impl RefUnwindSafe for Relational
impl Send for Relational
impl Sync for Relational
impl Unpin for Relational
impl UnwindSafe for Relational
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.