2020-01-30 07:19:59 +00:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! enum_from_u32 {
|
|
|
|
($(#[$attr:meta])* pub enum $name:ident {
|
2021-02-28 19:53:55 +00:00
|
|
|
$($(#[$var_attr:meta])* $variant:ident = $e:expr,)*
|
2020-01-30 07:19:59 +00:00
|
|
|
}) => {
|
|
|
|
$(#[$attr])*
|
|
|
|
pub enum $name {
|
2021-02-28 19:53:55 +00:00
|
|
|
$($(#[$var_attr])* $variant = $e),*
|
2020-01-30 07:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl $name {
|
|
|
|
pub fn from_u32(u: u32) -> Option<$name> {
|
|
|
|
$(if u == $name::$variant as u32 {
|
|
|
|
return Some($name::$variant)
|
|
|
|
})*
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
($(#[$attr:meta])* pub enum $name:ident {
|
2021-02-28 19:53:55 +00:00
|
|
|
$($(#[$var_attr:meta])* $variant:ident,)*
|
2020-01-30 07:19:59 +00:00
|
|
|
}) => {
|
|
|
|
$(#[$attr])*
|
|
|
|
pub enum $name {
|
2021-02-28 19:53:55 +00:00
|
|
|
$($(#[$var_attr])* $variant,)*
|
2020-01-30 07:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl $name {
|
|
|
|
pub fn from_u32(u: u32) -> Option<$name> {
|
|
|
|
$(if u == $name::$variant as u32 {
|
|
|
|
return Some($name::$variant)
|
|
|
|
})*
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|