2 stable releases

1.0.1 Jul 31, 2023
1.0.0 Oct 3, 2022

#1214 in Rust patterns

Download history 3113/week @ 2024-09-22 2705/week @ 2024-09-29 2030/week @ 2024-10-06 2666/week @ 2024-10-13 2924/week @ 2024-10-20 2937/week @ 2024-10-27 2744/week @ 2024-11-03 2477/week @ 2024-11-10 2450/week @ 2024-11-17 1904/week @ 2024-11-24 1906/week @ 2024-12-01 2213/week @ 2024-12-08 2328/week @ 2024-12-15 2141/week @ 2024-12-22 781/week @ 2024-12-29 578/week @ 2025-01-05

5,917 downloads per month
Used in 7 crates (6 directly)

MIT license

3KB

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

lib.rs:

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

No runtime deps