const_assert/
lib.rs

1//!
2//! Assert is used to create generic trait bounds:
3//!
4//! ```
5//! #![allow(incomplete_features)]
6//! #![feature(generic_const_exprs)]
7//!
8//! use const_assert::{Assert, IsTrue, IsFalse};
9//!
10//! struct Buffer<const N: usize> {
11//!   inner: [usize; N],
12//! }
13//!
14//! impl<const N: usize> Buffer<N>
15//! where
16//!   Assert<{ N == N.next_power_of_two() }>: IsTrue,
17//!   Assert<{ N == 1 }>: IsFalse
18//! {
19//!   pub const fn new() -> Self {
20//!       Buffer { inner: [0; N] }
21//!   }
22//! }
23//!
24//! static BUFFER: Buffer<1024> = Buffer::new();
25//! ```
26
27#![allow(incomplete_features)]
28#![feature(generic_const_exprs)]
29
30#![no_std]
31
32pub struct Assert<const COND: bool> {}
33
34pub trait IsTrue {}
35
36impl IsTrue for Assert<true> {}
37
38pub trait IsFalse {}
39
40impl IsFalse for Assert<false> {}