2019-05-21 17:14:09 +02:00
|
|
|
/// A simple static assertion macro.
|
2018-11-09 09:57:02 +11:00
|
|
|
#[macro_export]
|
2019-07-04 10:05:50 -04:00
|
|
|
#[allow_internal_unstable(type_ascription)]
|
2018-11-09 09:57:02 +11:00
|
|
|
macro_rules! static_assert {
|
2019-05-21 08:51:18 +02:00
|
|
|
($test:expr) => {
|
2018-11-09 09:57:02 +11:00
|
|
|
// Use the bool to access an array such that if the bool is false, the access
|
|
|
|
// is out-of-bounds.
|
|
|
|
#[allow(dead_code)]
|
2019-05-21 08:51:18 +02:00
|
|
|
const _: () = [()][!($test: bool) as usize];
|
2018-11-09 09:57:02 +11:00
|
|
|
}
|
|
|
|
}
|
2019-05-19 13:59:44 +03:00
|
|
|
|
|
|
|
/// Type size assertion. The first argument is a type and the second argument is its expected size.
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! static_assert_size {
|
|
|
|
($ty:ty, $size:expr) => {
|
|
|
|
const _: [(); $size] = [(); ::std::mem::size_of::<$ty>()];
|
|
|
|
}
|
|
|
|
}
|