metrics_evaluation/
compare.rs1use crate::{value::Value, Calculation};
2
3#[derive(Debug, Clone, Copy, PartialEq)]
5pub enum Logic {
6 And,
7 Or,
8}
9
10#[derive(Debug, PartialEq, Clone, Copy)]
12pub enum Operator {
13 Equal, NotEqual, GreaterEqual, LessEqual, Greater, Less, }
20
21pub trait Compareable {
23 fn compare(&self, other: &Self, operator: Operator) -> bool;
25}
26
27#[derive(Debug, PartialEq)]
29pub enum ComparisonType {
30 Value(Value, Vec<Calculation>),
32 Variable(String, Vec<Calculation>),
34}
35
36impl ComparisonType {
37 pub fn with_calculation(&mut self, calculation: Calculation) {
38 match self {
39 Self::Value(_, calculations) => calculations.push(calculation),
40 Self::Variable(_, calculations) => calculations.push(calculation),
41 }
42 }
43}
44
45#[derive(Debug, PartialEq)]
46pub struct Comparison {
47 pub what: ComparisonType,
49 pub operator: Operator,
51 pub against: ComparisonType,
53}
54
55impl From<(&str, Operator, Value)> for Comparison {
57 fn from((variable_name, operator, value): (&str, Operator, Value)) -> Self {
58 Self {
59 what: ComparisonType::Variable(variable_name.into(), Vec::new()),
60 operator,
61 against: ComparisonType::Value(value, Vec::new()),
62 }
63 }
64}
65
66impl From<(&str, Operator, &str)> for Comparison {
68 fn from((variable_name, operator, against_variable_name): (&str, Operator, &str)) -> Self {
69 Self {
70 what: ComparisonType::Variable(variable_name.into(), Vec::new()),
71 operator,
72 against: ComparisonType::Variable(against_variable_name.into(), Vec::new()),
73 }
74 }
75}