#enum #equality #macro #derive #partialeq

nightly macro varianteq

Derive the equality of enum variants ignoring fields

7 releases (4 breaking)

✓ Uses Rust 2018 edition

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

#231 in Rust patterns

28 downloads per month

MIT license

6KB

VariantEq

Latest Version Rust Documentation Build Status

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

~1MB
~25K SLoC