Add const assert macro for some static checks
diff --git a/src/assert.rs b/src/assert.rs
new file mode 100644
index 0000000..6159ce6
--- /dev/null
+++ b/src/assert.rs
@@ -0,0 +1,30 @@
+pub struct True;
+pub struct False;
+
+pub trait ToBool {
+ type Bool: Sized;
+ const BOOL: Self::Bool;
+}
+
+impl ToBool for [(); 0] {
+ type Bool = False;
+ const BOOL: Self::Bool = False;
+}
+
+impl ToBool for [(); 1] {
+ type Bool = True;
+ const BOOL: Self::Bool = True;
+}
+
+macro_rules! bool {
+ ($e:expr) => {{
+ const EXPR: bool = $e;
+ <[(); EXPR as usize] as $crate::assert::ToBool>::BOOL
+ }};
+}
+
+macro_rules! const_assert {
+ ($e:expr) => {
+ const _: $crate::assert::True = bool!($e);
+ };
+}