assert_sameish

Macro assert_sameish 

Source
macro_rules! assert_sameish {
    ($left:expr, $right:expr $(,)?) => { ... };
    ($left:expr, $right:expr, $($arg:tt)+) => { ... };
}
Expand description

Asserts that two values of potentially different types are structurally the same.

Unlike assert_same!, this allows comparing values of different types. Two values are “sameish” if they have the same structure and values, even if they have different type names.

Note: Because the two arguments can have different types, the compiler cannot infer types from one side to the other. If you get type inference errors, either add type annotations or use assert_same! instead.

§Panics

Panics if the values are not structurally same, displaying a colored diff.

§Example

use facet::Facet;
use facet_assert::assert_sameish;

#[derive(Facet)]
struct PersonV1 {
    name: String,
    age: u32,
}

#[derive(Facet)]
struct PersonV2 {
    name: String,
    age: u32,
}

let old = PersonV1 { name: "Alice".into(), age: 30 };
let new = PersonV2 { name: "Alice".into(), age: 30 };
assert_sameish!(old, new); // Different types, same structure