| David Tolnay | da5bd27 | 2020-03-16 21:53:22 -0700 | [diff] [blame^] | 1 | pub struct True; |
| 2 | pub struct False; |
| 3 | |
| 4 | pub trait ToBool { |
| 5 | type Bool: Sized; |
| 6 | const BOOL: Self::Bool; |
| 7 | } |
| 8 | |
| 9 | impl ToBool for [(); 0] { |
| 10 | type Bool = False; |
| 11 | const BOOL: Self::Bool = False; |
| 12 | } |
| 13 | |
| 14 | impl ToBool for [(); 1] { |
| 15 | type Bool = True; |
| 16 | const BOOL: Self::Bool = True; |
| 17 | } |
| 18 | |
| 19 | macro_rules! bool { |
| 20 | ($e:expr) => {{ |
| 21 | const EXPR: bool = $e; |
| 22 | <[(); EXPR as usize] as $crate::assert::ToBool>::BOOL |
| 23 | }}; |
| 24 | } |
| 25 | |
| 26 | macro_rules! const_assert { |
| 27 | ($e:expr) => { |
| 28 | const _: $crate::assert::True = bool!($e); |
| 29 | }; |
| 30 | } |