7 releases (4 breaking)
0.5.0 | Feb 10, 2019 |
---|---|
0.4.1 | Jun 2, 2018 |
0.4.0 | May 9, 2018 |
0.3.0 | May 6, 2018 |
0.1.1 | Apr 22, 2018 |
#1122 in Procedural macros
6KB
VariantEq
This crate provides a macro to implement equality of enum variants.
Two enum variants are equal if they are the same variant from the same enum, regardless of the values of the fields each variant contains.
#[derive(VariantEq)]
enum Enum {
Variant,
}
Examples
#[macro_use]
extern crate varianteq;
#[derive(Debug, VariantEq)]
enum E {
A(i32),
B(i32),
C(u32, bool),
}
fn main() {
assert_eq!(E::A(1), E::A(2));
assert_ne!(E::A(1), E::B(1));
assert_ne!(E::A(1), E::C(1, false));
}
Errors
The VariantEq
macro only applies to enums and will cauase a compilation error if used on
structs.
#[derive(VariantEq)]
struct S;
error: #[derive(VariantEq)] is only defined for enums
Dependencies
~2MB
~47K SLoC