Created
April 22, 2018 05:10
-
-
Save Lokathor/5ebb3766a8f9070d1a961664e51d0b46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro_rules! c_enum { | |
( | |
($count:expr) ? $enum_repr:ty ; $current:ident , $($rest:tt)* | |
) => { | |
pub const $current : $enum_repr = $count; | |
c_enum!( ($count + 1) ? $enum_repr ; $($rest)*); | |
}; | |
( | |
($count:expr) ? $enum_repr:ty ; $current:ident $($rest:tt)* | |
) => { | |
pub const $current : $enum_repr = $count; | |
}; | |
( | |
$(#[$enum_attributes:meta])* $enum_name:ident , $enum_repr:ty ; $($capture:tt)* | |
) => { | |
$(#[$enum_attributes:meta])* pub type $enum_name = $enum_repr; | |
c_enum!( (0) ? $enum_repr ; $($capture)*); | |
}; | |
} | |
c_enum!(AssetState, usize; AssetState_Unloaded, AssetState_Queued, AssetState_Loaded, AssetState_Locked); | |
fn main() { | |
for &state in [AssetState_Unloaded, AssetState_Queued, AssetState_Loaded, AssetState_Locked].iter() { | |
println!("{}", state); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment