5 releases

0.1.4 Dec 27, 2024
0.1.3 Dec 15, 2024
0.1.2 Dec 15, 2024
0.1.1 Dec 12, 2024
0.1.0 Dec 12, 2024

#930 in Rust patterns

Download history 268/week @ 2024-12-11 22/week @ 2024-12-18 144/week @ 2024-12-25 9/week @ 2025-01-08

186 downloads per month

MIT license

7KB
105 lines

enum-unit

Crate

Description

Generates unit-variant enums from existing enums.

Example

use enum_unit::*;

#[derive(EnumUnit)]
enum Example {
    A(i16),
    B { id: u8 },
}

fn main() {
    let a = Example::A(-420);
    assert_eq!(ExampleUnit::A, a.into());

    let b = Example::B { id: 69 };
    assert_eq!(ExampleUnit::B, b.into());
}

Features

Enable the bitflag feature to use the enum-units as bitflags as well.

Dependencies

~230–700KB
~17K SLoC