macro_rules! const_enum {
{
$( #[$enummeta:meta] )*
enum $name:ident, $path:path, $prefix:ident {
$(
$( #[$meta:meta] )*
$c:ident
),* $(,)?
}} => { ... };
}
Expand description
Turns FFI constants into an enum, freely convertible to and from u32. An extra variant Other(u32) exists to contain values not known to this num. The parameters are: Enum name, path to constants, constant prefix.
use const_enum::const_enum;
mod sys {
pub const NAME_B: u32 = 1;
}
const_enum! {
// you can also use "this" as the path if the constants are in the same scope. It doesn't work in doctests, though, so I added the "mod sys".
enum TestEnum, sys, NAME_ {
B,
}
}