Skip to content

Instantly share code, notes, and snippets.

@Lokathor
Created April 22, 2018 05:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lokathor/5ebb3766a8f9070d1a961664e51d0b46 to your computer and use it in GitHub Desktop.
Save Lokathor/5ebb3766a8f9070d1a961664e51d0b46 to your computer and use it in GitHub Desktop.
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