light_enum 0.1.0

provide a derive keyword to generate a light enum
Documentation

light_enum

crates.io docs.rs license

A crate providing a derive keyword to generate a light enum.

Usage

cargo add light_enum

Add #[derive(LightEnum)] on top of your enum.

Example

use light_enum::LightEnum;

#[derive(LightEnum)]
enum MyEnum {
    A(i32),
    B(i32),
    C(i32),
}

pub fn main() {
    let heavy = MyEnum::A(0);
    let light = heavy.to_light();

    assert!(light == MyEnumLight::A);
}

MyEnumLight will be generated:

enum MyEnumLight {
    A,
    B,
    C,
}

Note

Having a field without content in your enum will not compile. The macro doesn't support it.

// this code will not compile
#[derive(LightEnum)]
enum MyEnum {
    A,
}

Dev

The cargo expand utility is useful to see what is generated.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.