Crate assert_eq

Crate assert_eq 

Source
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§

AssertPath
A path to a field in a nested structure, used for error reporting.
AssertPathGuard
The guard returned by AssertPath::__guard, which pops the last segment when dropped.

Traits§

AssertEq
Trait for types that can be compared for equality with location-aware error reporting.

Derive Macros§

AssertEq
Derive macro for the AssertEq trait.