pub struct BitSet<'a> { /* private fields */ }Expand description
Compact bit array overlaid on a byte slice.
- O(1) get/set/clear/toggle per bit
- No overhead – 1 bit per flag
- Used for feature flags, user permission masks, state bitfields
Implementations§
Source§impl<'a> BitSet<'a>
impl<'a> BitSet<'a>
Sourcepub fn from_bytes(data: &'a mut [u8]) -> Self
pub fn from_bytes(data: &'a mut [u8]) -> Self
Overlay a BitSet on a mutable byte slice.
Sourcepub fn count_ones(&self) -> usize
pub fn count_ones(&self) -> usize
Count the number of set bits (popcount).
Sourcepub fn count_zeros(&self) -> usize
pub fn count_zeros(&self) -> usize
Count the number of clear bits.
Sourcepub fn check_flags(
&self,
byte_offset: usize,
required: u8,
) -> Result<(), ProgramError>
pub fn check_flags( &self, byte_offset: usize, required: u8, ) -> Result<(), ProgramError>
Check if ALL bits in a mask are set (starting at byte offset).
Sourcepub fn check_any_flag(
&self,
byte_offset: usize,
any_of: u8,
) -> Result<(), ProgramError>
pub fn check_any_flag( &self, byte_offset: usize, any_of: u8, ) -> Result<(), ProgramError>
Check if ANY bit in a mask is set.
Sourcepub const fn required_bytes(num_bits: usize) -> usize
pub const fn required_bytes(num_bits: usize) -> usize
Compute the byte size needed for a BitSet with the given number of bits.
Auto Trait Implementations§
impl<'a> Freeze for BitSet<'a>
impl<'a> RefUnwindSafe for BitSet<'a>
impl<'a> Send for BitSet<'a>
impl<'a> Sync for BitSet<'a>
impl<'a> Unpin for BitSet<'a>
impl<'a> UnsafeUnpin for BitSet<'a>
impl<'a> !UnwindSafe for BitSet<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more