const-assert

Crates.ioconst-assert
lib.rsconst-assert
version1.0.1
sourcesrc
created_at2022-10-03 02:18:02.146351
updated_at2023-07-31 16:33:50.005876
descriptionAssert struct for const generics
homepage
repositoryhttps://github.com/Bajix/const-assert/
max_upload_size
id678659
size4,011
Thomas Sieverding (Bajix)

documentation

README

License Cargo Documentation

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();
Commit count: 6

cargo fmt