Expand description
Location-aware equality assertions.
This library provides the AssertEq trait and the assert_eq! and debug_assert_eq! macros.
The main feature is that when an assertion fails, the error message includes the path to the field that failed, making it much easier to debug complex nested structures.
§Example
ⓘ
use assert_eq::AssertEq;
#[derive(AssertEq, Debug)]
struct Inner {
a: i32,
b: String,
}
#[derive(AssertEq, Debug)]
struct Outer {
x: Inner,
y: Vec<i32>,
}
let a = Outer {
x: Inner { a: 1, b: "hello".to_owned() },
y: vec![1, 2, 3],
};
let b = Outer {
x: Inner { a: 1, b: "world".to_owned() },
y: vec![1, 2, 3],
};
assert_eq::assert_eq!(a, b);Macros§
- assert_
eq - A macro to assert that two values are equal, with location-aware error reporting.
- debug_
assert_ eq - A macro to assert that two values are equal in debug builds, with location-aware error reporting.
Structs§
- Assert
Path - A path to a field in a nested structure, used for error reporting.
- Assert
Path Guard - The guard returned by
AssertPath::__guard, which pops the last segment when dropped.
Traits§
- Assert
Eq - Trait for types that can be compared for equality with location-aware error reporting.