1 /// A simple static assertion macro.
3 #[allow_internal_unstable(type_ascription)]
4 macro_rules! static_assert {
6 // Use the bool to access an array such that if the bool is false, the access
9 const _: () = [()][!($test: bool) as usize];
13 /// Type size assertion. The first argument is a type and the second argument is its expected size.
15 macro_rules! static_assert_size {
16 ($ty:ty, $size:expr) => {
17 const _: [(); $size] = [(); ::std::mem::size_of::<$ty>()];
22 macro_rules! enum_from_u32 {
23 ($(#[$attr:meta])* pub enum $name:ident {
24 $($variant:ident = $e:expr,)*
32 pub fn from_u32(u: u32) -> Option<$name> {
33 $(if u == $name::$variant as u32 {
34 return Some($name::$variant)
40 ($(#[$attr:meta])* pub enum $name:ident {
49 pub fn from_u32(u: u32) -> Option<$name> {
50 $(if u == $name::$variant as u32 {
51 return Some($name::$variant)