reactive_graph_behaviour_model_impl/entity/
expression.rs

1use strum::EnumString;
2
3/// Represents the an expression with a left hand side and a right hand side.
4#[derive(Debug, PartialEq, EnumString)]
5pub enum OperatorPosition {
6    LHS,
7    RHS,
8}
9
10pub type ExpressionValue<T> = (OperatorPosition, T);
11
12/// Represents an expression with a left hand side and a right hand side.
13#[derive(Copy, Clone, Debug)]
14pub struct Expression<LHS, RHS> {
15    /// The left hand side of the expression.
16    pub lhs: LHS,
17
18    /// The right hand side of the expression.
19    pub rhs: RHS,
20}
21
22impl<LHS: Clone, RHS: Clone> Expression<LHS, RHS> {
23    pub fn new(lhs: LHS, rhs: RHS) -> Self {
24        Expression { lhs, rhs }
25    }
26
27    #[must_use]
28    pub fn lhs(&self, lhs: LHS) -> Self {
29        Expression::new(lhs, self.rhs.clone())
30    }
31
32    #[must_use]
33    pub fn rhs(&self, rhs: RHS) -> Self {
34        Expression::new(self.lhs.clone(), rhs)
35    }
36}
37
38#[derive(Clone, Debug)]
39pub struct ExpressionResult<T, LHS, RHS> {
40    /// Textual representation of the operator, for example "&&" for an AND-operator
41    pub symbol: String,
42
43    /// The expression
44    pub expression: Expression<LHS, RHS>,
45
46    /// The calculated result
47    pub result: T,
48}