json_eval_rs/rlogic/evaluator/
comparison.rs1use super::{Evaluator, types::*};
2use serde_json::Value;
3use super::super::compiled::CompiledLogic;
4use super::helpers;
5
6impl Evaluator {
7 #[inline]
9 pub(super) fn eval_binary_compare(&self, op: CompOp, a: &CompiledLogic, b: &CompiledLogic, user_data: &Value, internal_context: &Value, depth: usize) -> Result<Value, String> {
10 let val_a = self.evaluate_with_context(a, user_data, internal_context, depth + 1)?;
11 let val_b = self.evaluate_with_context(b, user_data, internal_context, depth + 1)?;
12 let result = match op {
13 CompOp::Eq => helpers::loose_equal(&val_a, &val_b),
14 CompOp::StrictEq => val_a == val_b,
15 CompOp::Ne => !helpers::loose_equal(&val_a, &val_b),
16 CompOp::StrictNe => val_a != val_b,
17 CompOp::Lt => helpers::compare(&val_a, &val_b) < 0.0,
18 CompOp::Le => helpers::compare(&val_a, &val_b) <= 0.0,
19 CompOp::Gt => helpers::compare(&val_a, &val_b) > 0.0,
20 CompOp::Ge => helpers::compare(&val_a, &val_b) >= 0.0,
21 };
22 Ok(Value::Bool(result))
23 }
24}