#derive #library #rust

macro stupid-from-num

Auto implement From trait on an enum

1 unstable release

0.1.0 Nov 8, 2023

#289 in #library

Download history 5/week @ 2024-02-18 13/week @ 2024-02-25 1/week @ 2024-03-03 54/week @ 2024-03-24 17/week @ 2024-03-31 1/week @ 2024-04-07

72 downloads per month
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

~310–760KB
~18K SLoC