3 releases (stable)
1.1.1 | Oct 24, 2023 |
---|---|
0.1.0 | Oct 9, 2023 |
#872 in Procedural macros
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.8MB
~19K SLoC