Function strict_eq

Source
pub fn strict_eq(first: &Value, second: &Value) -> bool
Expand description

Perform JS-style strict equality

Items are strictly equal if:

  • They are the same non-primitive object
  • They are a primitive object of the same type with the same value
use serde_json::json;
use jsonlogic_rs::js_op::strict_eq;

// References of the same type and value are strictly equal
assert!(strict_eq(&json!(1), &json!(1)));
assert!(strict_eq(&json!(false), &json!(false)));
assert!(strict_eq(&json!("foo"), &json!("foo")));

// "Abstract" type conversion is not performed for strict equality
assert!(!strict_eq(&json!(0), &json!(false)));
assert!(!strict_eq(&json!(""), &json!(0)));

// Objects only compare equal if they are the same reference
assert!(!strict_eq(&json!([]), &json!([])));
assert!(!strict_eq(&json!({}), &json!({})));

let arr = json!([]);
let obj = json!({});
assert!(strict_eq(&arr, &arr));
assert!(strict_eq(&obj, &obj));