Skip to main content

apply_equal

Function apply_equal 

Source
pub fn apply_equal(left: &Value, right: &Value) -> bool
Expand description

Apply equality comparison between two values

Compares two Value instances for equality, handling proper type matching. Cross-type integer comparisons (Uint vs Int) are supported via i128 coercion. Incompatible types (e.g., string vs integer) are considered unequal.

§Arguments

  • left - The left-hand side value (typically from file data)
  • right - The right-hand side value (typically from magic rule)

§Returns

true if the values are equal (including cross-type integer coercion), false otherwise

§Examples

use libmagic_rs::parser::ast::Value;
use libmagic_rs::evaluator::operators::apply_equal;

// Same type, same value
assert!(apply_equal(&Value::Uint(42), &Value::Uint(42)));

// Same type, different value
assert!(!apply_equal(&Value::Uint(42), &Value::Uint(24)));

// Cross-type integer coercion
assert!(apply_equal(&Value::Uint(42), &Value::Int(42)));

// String comparison
assert!(apply_equal(
    &Value::String("hello".to_string()),
    &Value::String("hello".to_string())
));