#![no_std]
use core::ops::RangeBounds;
pub trait Bits {
type Bits;
const N_BITS: u32;
fn bit<I>(self, i: I) -> bool
where
I: BitsIndex<Self>,
Self: Sized;
fn bits<I, R>(self, range: R) -> Self::Bits
where
I: BitsIndex<Self>,
R: RangeBounds<I>,
Self: Sized;
fn set_bit<I>(&mut self, i: I, bit: bool)
where
I: BitsIndex<Self>,
Self: Sized;
fn set_bits<I, R>(&mut self, range: R, bits: Self::Bits)
where
I: BitsIndex<Self>,
R: RangeBounds<I>,
Self: Sized;
fn with_bit<I>(self, i: I, bit: bool) -> Self
where
I: BitsIndex<Self>,
Self: Sized;
fn with_bits<I, R>(self, range: R, bits: Self::Bits) -> Self
where
I: BitsIndex<Self>,
R: RangeBounds<I>,
Self: Sized;
}
pub trait BitsIndex<T> {
fn bit(value: T, index: Self) -> bool;
fn bits<R>(value: T, range: R) -> <T as Bits>::Bits
where
T: Bits,
R: RangeBounds<Self>;
fn set_bit(value: &mut T, index: Self, bit: bool);
fn set_bits<R>(value: &mut T, range: R, bits: <T as Bits>::Bits)
where
T: Bits,
R: RangeBounds<Self>;
}
mod impls;
#[cfg(test)]
mod test;