#derive #library #rust

macro stupid-from-num

Auto implement From trait on an enum

1 unstable release

0.1.0 Nov 8, 2023

#299 in #library


Used in dbeel

Apache-2.0 OR MIT

5KB
69 lines

A derive macro that adds a impl From<u8> to any enum.

If the number of items is bigger than u8::MAX, it will use u16, then u32 if bigger than u16::MAX.

Example:

use stupid_from_num::FromNum;

#[derive(FromNum)]
enum Example {
    Zero,
    One,
    Two,
}

assert_eq!(Example::Zero.into(), 0);
assert_eq!(Example::One.into(), 1);
assert_eq!(Example::Two.into(), 2);

Dependencies

~235–680KB
~16K SLoC