bit-bounds

Crates.iobit-bounds
lib.rsbit-bounds
version1.0.0
sourcesrc
created_at2022-10-15 13:49:52.39696
updated_at2024-03-19 22:59:50.711789
descriptionHelper traits for const generic bitwise bounds
homepage
repositoryhttps://github.com/Bajix/bit-bounds/
max_upload_size
id688977
size5,399
Thomas Sieverding (Bajix)

documentation

README

License Cargo Documentation

Helper traits for const generic bitwise bounds

#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

use bit_bounds::{IsPowerOf2, usize::*};

struct Buffer<const N: usize> {
  inner: [usize; N],
}

impl<const N: usize> Buffer<N>
where
  Int<N>: IsPowerOf2
{
  pub const fn new() -> Self {
    Buffer { inner: [0; N] }
  }
}

fn extract_index<const N: usize>(counter: usize) -> usize
where
  Int<N>: IsPowerOf2,
  Int<N>: BitsAllClear<{ (u32::MAX as usize) << 32 }>,
{
  (counter >> 32) & (N - 1)
}
Commit count: 4

cargo fmt