Struct bit_array_rs::BitArray
source · pub struct BitArray { /* private fields */ }
Implementations§
source§impl BitArray
impl BitArray
sourcepub fn first_unset_bit(&self) -> Option<usize>
pub fn first_unset_bit(&self) -> Option<usize>
Finds the first bit that is not set in the array.
§Returns
- The index of the first unset bit, or
None
if all bits are set.
sourcepub fn first_set_bit(&self) -> Option<usize>
pub fn first_set_bit(&self) -> Option<usize>
Finds the first bit that is set in the array.
§Returns
- The index of the first set bit, or
None
if no bits are set.
sourcepub fn count_set_bits(&self) -> usize
pub fn count_set_bits(&self) -> usize
Returns the number of bits that are currently set to 1
.
§Returns
The number of bits that are set in the BitArray
.
sourcepub fn bit_count(&self) -> usize
pub fn bit_count(&self) -> usize
Returns the total number of bits in the BitArray
.
§Returns
The total number of bits in the BitArray
.
sourcepub fn atom_from_index(&self, from_index: usize) -> u32
pub fn atom_from_index(&self, from_index: usize) -> u32
Trait Implementations§
source§impl Debug for BitArray
impl Debug for BitArray
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the BitArray
as a binary string with groups of 8 bits separated by a space.
§Arguments
f
- The formatter used to output the debug string.
§Returns
A Result
indicating whether the formatting was successful.
§Example
use bit_array_rs::BitArray;
let mut bit_array = BitArray::new(16);
bit_array.set(3);
bit_array.set(7);
bit_array.set(9);
bit_array.set(15);
assert_eq!(format!("{:?}", bit_array), "00010001 01000001");
source§impl Display for BitArray
impl Display for BitArray
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the BitArray
as a continuous binary string without any spaces.
§Arguments
f
- The formatter used to output the display string.
§Returns
A Result
indicating whether the formatting was successful.
§Example
use bit_array_rs::BitArray;
let mut bit_array = BitArray::new(16);
bit_array.set(3);
bit_array.set(7);
bit_array.set(9);
bit_array.set(15);
assert_eq!(format!("{}", bit_array), "0001000101000001");
source§impl Index<usize> for BitArray
impl Index<usize> for BitArray
source§fn index(&self, index: usize) -> &Self::Output
fn index(&self, index: usize) -> &Self::Output
Provides indexed access to individual bits in the BitArray
.
§Arguments
index
- The zero-based index of the bit to access.
§Returns
A reference to a boolean value (true
or false
) representing the state of the bit
at the specified index.
§Panics
This function will panic if the index
is out of bounds.
§Example
use bit_array_rs::BitArray;
let mut bit_array = BitArray::new(16);
bit_array.set(3);
assert_eq!(bit_array[3], true);
assert_eq!(bit_array[0], false);
Auto Trait Implementations§
impl Freeze for BitArray
impl RefUnwindSafe for BitArray
impl Send for BitArray
impl Sync for BitArray
impl Unpin for BitArray
impl UnwindSafe for BitArray
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)