varianteq

Crates.iovarianteq
lib.rsvarianteq
version0.5.0
sourcesrc
created_at2018-04-21 13:02:16.766643
updated_at2019-02-10 10:32:35.648375
descriptionDerive the equality of enum variants ignoring fields
homepage
repositoryhttps://github.com/joshleeb/varianteq
max_upload_size
id61701
size10,725
Josh Leeb-du Toit (joshleeb)

documentation

https://docs.rs/crate/varianteq/

README

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
Commit count: 42

cargo fmt