bitable 0.1.0

An all-const, compile-time checked, safe bit handling library with zero runtime overhead
Documentation
use super::common::*;
use super::set::Set;

/// A generic bit mask of type `T`
#[repr(transparent)]
#[derive(Debug)] //, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Mask {
    mask: UReg,
}

#[allow(private_bounds)]
impl const Mask
{
    pub fn apply<In, Out, const OFFSET: u8, const SIZE: u8>(&self, bitset: &In) -> UReg
    where In: const Set<Out, OFFSET, SIZE>,
          Out: const CastFromUReg,
    {
        let _ = <In>::ASSERT_MASK;
        bitset.read() & self.mask
    }

    pub fn apply_at<In, Out, const OFFSET: u8, const SIZE: u8>(&self, bitset: &In, idx: usize) -> UReg
    where In: const Set<Out, OFFSET, SIZE>,
          Out: const CastFromUReg,
    {
        let _ = <In>::ASSERT_MASK;
        bitset.read_at(idx) & self.mask
    }

    pub fn new(mask: UReg) -> Self {
        Self { mask }
    }
}

// ---------------------------------------------------------------------------
// Conversion between core types
// ---------------------------------------------------------------------------

impl const From<Mask> for UReg {
    fn from(bitmask: Mask) -> Self {
        bitmask.mask
    }
}