4 releases (2 breaking)

0.3.0 Aug 3, 2024
0.2.0 Apr 15, 2024
0.1.1 Apr 15, 2024
0.1.0 Apr 15, 2024

#66 in #enum

33 downloads per month
Used in 2 crates (via dalet)

MIT license

5KB
70 lines

enum-procs

Useful enum macros

crates.io

AutoFrom

Derive macro generating an impl of the trait From for all types inside tuple variants with one type

use enum_procs::AutoFrom;

#[derive(AutoFrom, Debug, PartialEq, Eq)]
enum Test {
    Bool(bool),
    Text(String),
}

assert_eq!(Test::from(true), Test::Bool(true));
assert_eq!(Test::from("Test"), Test::Text("Test".to_owned()));

PartialEqVariant

Derive macro generating an impl of the trait PartialEq that compare enum only by variant

use enum_procs::PartialEqVariant;

#[derive(PartialEqVariant, Eq)]
enum EnumProc {
    VariantWithValue(bool),
    AnotherVariantWithValue(bool),
}

assert!(EnumProc::VariantWithValue(true) == EnumProc::VariantWithValue(false));
assert!(EnumProc::VariantWithValue(false) == EnumProc::VariantWithValue(true));

Dependencies

~215–660KB
~16K SLoC