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