3 releases (stable)

1.1.1 Oct 24, 2023
0.1.0 Oct 9, 2023

#470 in Procedural macros

Download history 5/week @ 2024-02-16 9/week @ 2024-02-23 1/week @ 2024-03-01 2/week @ 2024-03-08 6/week @ 2024-03-15 42/week @ 2024-03-29 11/week @ 2024-04-05

53 downloads per month

MIT license

5KB
61 lines

Attribute macro,implementing the From trait for your Enum.

use from_num::from_num;
#[derive(Debug,PartialEq)]
#[from_num(i8,u64,usize)]
enum Planet {
    Mercury,
    Venus,
    Earth,
    Mars,
    Jupiter = 0b1000,
    Saturn,
    Uranus = 0xff,
    Neptune
}
pub fn get_from_number() {
    assert_eq!(Planet::Jupiter,Planet::from_i8(0b1000 as i8).unwrap());
    assert_eq!(Planet::Neptune,Planet::from_u64(256 as u64).unwrap());
}

Dependencies

~0.4–0.9MB
~20K SLoC