datex_core/traits/
structural_eq.rs

1use core::prelude::rust_2024::*;
2
3pub trait StructuralEq {
4    /// Check if two values are equal, ignoring the type.
5    fn structural_eq(&self, other: &Self) -> bool;
6}
7
8#[macro_export]
9macro_rules! assert_structural_eq {
10    ($left_val:expr, $right_val:expr $(,)?) => {
11        if !$left_val.structural_eq(&$right_val) {
12            core::panic!(
13                "structural equality assertion failed: `(left == right)`\n  left: `{:?}`,\n right: `{:?}`",
14                $left_val, $right_val
15            );
16        }
17    };
18}
19impl<T: StructuralEq> StructuralEq for Option<T> {
20    fn structural_eq(&self, other: &Self) -> bool {
21        match (self, other) {
22            (Some(a), Some(b)) => a.structural_eq(b),
23            (None, None) => {
24                core::todo!("#350 decide if None is structurally equal to None")
25            }
26            _ => false,
27        }
28    }
29}