| Crates.io | const-assert |
| lib.rs | const-assert |
| version | 1.0.1 |
| created_at | 2022-10-03 02:18:02.146351+00 |
| updated_at | 2023-07-31 16:33:50.005876+00 |
| description | Assert struct for const generics |
| homepage | |
| repository | https://github.com/Bajix/const-assert/ |
| max_upload_size | |
| id | 678659 |
| size | 4,011 |
Assert is used to create generic trait bounds:
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
use const_assert::{Assert, IsTrue, IsFalse};
struct Buffer<const N: usize> {
inner: [usize; N],
}
impl<const N: usize> Buffer<N>
where
Assert<{ N == N.next_power_of_two() }>: IsTrue,
Assert<{ N == 1 }>: IsFalse
{
pub const fn new() -> Self {
Buffer { inner: [0; N] }
}
}
static BUFFER: Buffer<1024> = Buffer::new();