const-assert 1.0.1

Assert struct for const generics
Documentation
  • Coverage
  • 25%
    1 out of 4 items documented1 out of 4 items with examples
  • Size
  • Source code size: 3.7 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 270.02 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Bajix/const-assert
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Bajix

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();