pub fn structural_equal<'l, 'r>(
lhs: impl Into<AnyView<'l>>,
rhs: impl Into<AnyView<'r>>,
) -> Result<bool>Expand description
Whether two values are structurally equal: they have the same structure and content, compared recursively through containers and reflected fields, not by identity.
Objects compare as their SEqHashKind declares.
§Arguments
lhs- The left value.rhs- The right value.
§Returns
Whether the values are structurally equal.
§Errors
Returns an error if an object in either value does not support structural equality.
§Examples
use tvm_ffi::derive::ObjectRef;
use tvm_ffi::{rs_object, structural_equal, Array, Object, ObjectArc};
#[rs_object(type_key = "my_ext.MyPair", final, s_eq_hash_kind = "TreeNode")]
pub struct MyPairObj {
base_: Object,
pub first: i64,
pub second: Array<i64>,
}
#[derive(Clone, ObjectRef)]
pub struct MyPair {
data: ObjectArc<MyPairObj>,
}
let pair = |second: Vec<i64>| {
MyPair::from_object(MyPairObj::new(Object::new(), 1, Array::from_vec(second)))
};
assert!(structural_equal(&pair(vec![2, 3]), &pair(vec![2, 3]))?);
assert!(!structural_equal(&pair(vec![2, 3]), &pair(vec![2, 4]))?);