expression/
lib.rs

1pub mod cond;
2
3use std::cmp::{PartialEq, PartialOrd};
4use std::fmt::Debug;
5
6#[derive(Debug, Eq, PartialEq)]
7pub enum ExpressionError {
8    /// In case of division by zero.
9    DivByZero,
10    /// In case an invalid variable in references from the expression.
11    InvalidVariable,
12    /// In case of an invalid operation.
13    InvalidOperation,
14}
15
16pub trait Expression: Debug + Clone + PartialEq {
17    type Element: Debug + Copy + Clone + PartialEq + PartialOrd;
18    /// Evaluates the expression with the given variables bound.
19    fn evaluate(&self, variables: &[Self::Element]) -> Result<Self::Element, ExpressionError>;
20}
21
22pub trait Condition: Debug + Clone + PartialEq {
23    type Expr: Expression;
24    /// Evaluate the condition with the given variables bound.
25    fn evaluate(
26        &self,
27        variables: &[<Self::Expr as Expression>::Element],
28    ) -> Result<bool, ExpressionError>;
29}