#variant #enums #derive #equals #macro

enum_variant_eq

Determining that enumerations only have Variant equal

1 unstable release

0.1.0 Mar 24, 2023

#23 in #equals

MIT license

6KB
79 lines

Determining that enumerations only have Variant equal

Examples

use enum_variant_eq::{*,enum_variant_eq_derive::*};

#[derive(Debug, EnumVariantEq)]
enum TestEnum {
    Unit,
    EmptyUnNamed(),
    UnNamed(i8),
    UnNamed2(i8, u8),
    EmptyNamed {},
    Named { x: i8 },
    Named2 { x: i8, y: u8 },
}
use TestEnum::*;
assert!(Unit.enum_variant_eq(&Unit));
assert!(UnNamed(5).enum_variant_eq(&UnNamed(8)));
assert!(Named { x: 5 }.enum_variant_eq(&Named { x: 8 }));

Errors

EnumVariantEq only applies to enumerations. If it is violated, the compilation will panic

#[derive(EnumVariantEq)]
struct S;
error: #[derive(Debug, EnumVariantEq)]
    |                  ^^^^^^^^^^^^^
    = help: message: Type Is Not Enum

Other:

Build Ast Error

Dependencies

~1.5MB
~37K SLoC