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