cmp
cmp is a Rust crate that provides a macro for comparing fields in structs, which is particularly useful when writing assert! tests.
Usage
use compare_structs;
compare_structs!
The compare_structs! macro compares specified fields of two structs. If the fields do not match, the macro will panic and output the fields that do not match.
Example
use compare_structs;
let struct_a = A ;
let struct_b = B ;
compare_structs!;
In this example, the compare_structs! macro compares the a and c fields of struct_a and struct_b. If they do not match, the macro will panic and output the fields that do not match.
Output
The output of the compare_structs! macro singles out the fields in the structs that do not match. For example:
(
)
(
)
(
)
(
)
In this output, the c field of the two structs do not match, and the macro outputs the differing values.
Features
serde- Allows
compare_structsto be called without specifying any fields - Adds
serdeandserde_jsonas dependencies
- Allows