Skip to content

Commit 2921cd0

Browse files
committed
Remove invalid metric checks from formula operations
Because each metric is now its own type, these checks are redundant and can be removed. Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
1 parent 0435296 commit 2921cd0

3 files changed

Lines changed: 0 additions & 34 deletions

File tree

src/error.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ ErrorKind!(
5858
(ChronoError, chrono_error),
5959
(DroppedUnusedFormulas, dropped_unused_formulas),
6060
(FormulaEngineError, formula_engine_error),
61-
(InvalidMetric, invalid_metric),
6261
(Internal, internal)
6362
);
6463

src/logical_meter/formula.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,6 @@ where
7979
let mut params_self: FormulaParams<T, M> = self.into();
8080
let params_other: FormulaParams<T, M> = other.into();
8181

82-
if params_self.metric != params_other.metric {
83-
return Err(Error::invalid_metric(format!(
84-
"Cannot coalesce formulas with different metrics: {} and {}",
85-
params_self.metric.as_str_name(),
86-
params_other.metric.as_str_name()
87-
)));
88-
}
8982
params_self.formula = params_self.formula.coalesce(params_other.formula);
9083
Ok(params_self.into())
9184
}
@@ -94,13 +87,6 @@ where
9487
let mut params_self: FormulaParams<T, M> = self.into();
9588
let params_other: FormulaParams<T, M> = other.into();
9689

97-
if params_self.metric != params_other.metric {
98-
return Err(Error::invalid_metric(format!(
99-
"Cannot take min of formulas with different metrics: {} and {}",
100-
params_self.metric.as_str_name(),
101-
params_other.metric.as_str_name()
102-
)));
103-
}
10490
params_self.formula = params_self.formula.min(params_other.formula);
10591
Ok(params_self.into())
10692
}
@@ -109,13 +95,6 @@ where
10995
let mut params_self: FormulaParams<T, M> = self.into();
11096
let params_other: FormulaParams<T, M> = other.into();
11197

112-
if params_self.metric != params_other.metric {
113-
return Err(Error::invalid_metric(format!(
114-
"Cannot take max of formulas with different metrics: {} and {}",
115-
params_self.metric.as_str_name(),
116-
params_other.metric.as_str_name()
117-
)));
118-
}
11998
params_self.formula = params_self.formula.max(params_other.formula);
12099
Ok(params_self.into())
121100
}

src/logical_meter/formula/aggregation_formula.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@ impl<M: Metric> std::ops::Add for AggregationFormula<M> {
7474
type Output = Result<Self, Error>;
7575

7676
fn add(self, other: Self) -> Self::Output {
77-
if self.metric != other.metric {
78-
return Err(Error::invalid_metric(format!(
79-
"Cannot add formulas with different metrics: {} and {}",
80-
self.metric as isize, other.metric as isize
81-
)));
82-
}
8377
let new_formula = self.formula + other.formula;
8478
Ok(FormulaParams::new(new_formula, self.metric, self.instructions_tx).into())
8579
}
@@ -89,12 +83,6 @@ impl<M: Metric> std::ops::Sub for AggregationFormula<M> {
8983
type Output = Result<Self, Error>;
9084

9185
fn sub(self, other: Self) -> Self::Output {
92-
if self.metric != other.metric {
93-
return Err(Error::invalid_metric(format!(
94-
"Cannot subtract formulas with different metrics: {} and {}",
95-
self.metric as isize, other.metric as isize
96-
)));
97-
}
9886
let new_formula = self.formula - other.formula;
9987
Ok(FormulaParams::new(new_formula, self.metric, self.instructions_tx).into())
10088
}

0 commit comments

Comments
 (0)