Macro mac_parser::enum_to_int
source · macro_rules! enum_to_int { ($a:ty, $b:ty, $($x:expr, $y:path), +) => { ... }; }
Expand description
This macro allows turning enums into numbers and vice versa.
#![feature(more_qualified_paths)]
#[derive(Debug, PartialEq)]
enum ABC {
A,
B,
C,
Unknown(u8),
}
bin_utils::enum_to_int! {
u8,
ABC,
0x01,
ABC::A,
0x02,
ABC::B,
0x03,
ABC::C
}
let a: ABC = 0x01.into();
assert_eq!(a, ABC::A);
let a: u8 = a.into();
assert_eq!(a, 0x01);
let unknown: ABC = 0xff.into();
assert_eq!(unknown, ABC::Unknown(0xff));