pub trait Bits: Sealed {
type IterOnes<'a>: Iterator<Item = u32>
where Self: 'a;
type IterOnesIn<'a, E>: Iterator<Item = u32>
where Self: 'a,
E: Endian;
type IterZeros<'a>: Iterator<Item = u32>
where Self: 'a;
type IterZerosIn<'a, E>: Iterator<Item = u32>
where Self: 'a,
E: Endian;
Show 21 methods
// Required methods
fn count_ones(&self) -> u32;
fn count_zeros(&self) -> u32;
fn bits_capacity(&self) -> u32;
fn all_zeros(&self) -> bool;
fn all_ones(&self) -> bool;
fn test_bit(&self, index: u32) -> bool;
fn test_bit_in<E>(&self, index: u32) -> bool
where E: Endian;
fn iter_ones(&self) -> Self::IterOnes<'_>;
fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>
where E: Endian;
fn iter_zeros(&self) -> Self::IterZeros<'_>;
fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>
where E: Endian;
// Provided methods
fn test_bit_le(&self, index: u32) -> bool { ... }
fn test_bit_be(&self, index: u32) -> bool { ... }
fn iter_ones_le(&self) -> Self::IterOnesIn<'_, LittleEndian> { ... }
fn iter_ones_be(&self) -> Self::IterOnesIn<'_, BigEndian> { ... }
fn iter_zeros_le(&self) -> Self::IterZerosIn<'_, LittleEndian> { ... }
fn iter_zeros_be(&self) -> Self::IterZerosIn<'_, BigEndian> { ... }
fn join_ones_in<I, E>(&self, iter: I) -> JoinOnes<'_, Self, E, I::IntoIter>
where I: IntoIterator,
E: Endian { ... }
fn join_ones<I>(
&self,
iter: I,
) -> JoinOnes<'_, Self, DefaultEndian, I::IntoIter>
where I: IntoIterator { ... }
fn join_ones_le<I>(
&self,
iter: I,
) -> JoinOnes<'_, Self, LittleEndian, I::IntoIter>
where I: IntoIterator { ... }
fn join_ones_be<I>(
&self,
iter: I,
) -> JoinOnes<'_, Self, BigEndian, I::IntoIter>
where I: IntoIterator { ... }
}
Expand description
Bitset immutable operations.
This is implemented for primitive types such as:
usize
,u32
,u64
, and other signed numbers.- Arrays made up of numerical primitives, such as
[u32; 32]
. - Slices of numerical primitives, such as
&[u32]
.
Also see the associated sibling traits:
§Examples
We can use the iterator of each set to compare bit sets of different kinds.
The Bits::iter_ones
iterator is guaranteed to iterate elements in the
same order:
use bittle::{Bits, BitsMut};
let a: [u64; 2] = bittle::set![111];
let mut b = 0u128;
assert!(!a.iter_ones().eq(b.iter_ones()));
b.set_bit(111);
assert!(a.iter_ones().eq(b.iter_ones()));
Required Associated Types§
Sourcetype IterOnes<'a>: Iterator<Item = u32>
where
Self: 'a
type IterOnes<'a>: Iterator<Item = u32> where Self: 'a
The iterator over zeros in this bit pattern using DefaultEndian
indexing.
See Bits::iter_ones
.
Sourcetype IterOnesIn<'a, E>: Iterator<Item = u32>
where
Self: 'a,
E: Endian
type IterOnesIn<'a, E>: Iterator<Item = u32> where Self: 'a, E: Endian
The iterator over ones in this bit pattern using custom Endian
indexing.
See Bits::iter_ones_in
.
Sourcetype IterZeros<'a>: Iterator<Item = u32>
where
Self: 'a
type IterZeros<'a>: Iterator<Item = u32> where Self: 'a
The iterator over zeros in this bit pattern using DefaultEndian
indexing.
See Bits::iter_zeros
.
Sourcetype IterZerosIn<'a, E>: Iterator<Item = u32>
where
Self: 'a,
E: Endian
type IterZerosIn<'a, E>: Iterator<Item = u32> where Self: 'a, E: Endian
The iterator over zeros in this bit pattern using custom Endian
indexing.
See Bits::iter_zeros_in
.
Required Methods§
Sourcefn count_ones(&self) -> u32
fn count_ones(&self) -> u32
Get the number of ones in the set.
§Examples
use bittle::{Bits, BitsMut};
let mut a = 0u128;
assert_eq!(a.count_ones(), 0);
a.set_bit(4);
assert_eq!(a.count_ones(), 1);
Using a larger set:
use bittle::{Bits, BitsMut};
let mut a = [0u128, 0];
assert_eq!(a.count_ones(), 0);
a.set_bit(240);
assert_eq!(a.count_ones(), 1);
Sourcefn count_zeros(&self) -> u32
fn count_zeros(&self) -> u32
Get the number of ones in the set.
§Examples
use bittle::{Bits, BitsMut};
let mut a = 0u128;
assert_eq!(a.count_zeros(), 128);
a.set_bit(4);
assert_eq!(a.count_zeros(), 127);
Using a larger set:
use bittle::{Bits, BitsMut};
let mut a = [0u128, 0];
assert_eq!(a.count_zeros(), 256);
a.set_bit(240);
assert_eq!(a.count_zeros(), 255);
Sourcefn bits_capacity(&self) -> u32
fn bits_capacity(&self) -> u32
Get the capacity of the underlying set.
§Examples
use bittle::Bits;
let mut set = 0u128;
assert_eq!(set.bits_capacity(), 128);
Using a larger set:
use bittle::Bits;
let mut set = [0u128, 0];
assert_eq!(set.bits_capacity(), 256);
Sourcefn all_zeros(&self) -> bool
fn all_zeros(&self) -> bool
Test if this set is empty, or all zeros.
§Examples
use bittle::Bits;
let a: u32 = bittle::set![];
assert!(a.all_zeros());
let a: u32 = bittle::set![1];
assert!(!a.all_zeros());
Using a larger set:
use bittle::Bits;
let a: [u32; 2] = bittle::set![];
assert!(a.all_zeros());
let a: [u32; 2] = bittle::set![55];
assert!(!a.all_zeros());
Sourcefn all_ones(&self) -> bool
fn all_ones(&self) -> bool
Test if bit set is full, or all ones.
§Examples
use bittle::{Bits, BitsMut, BitsOwned};
let mut set = u128::ones();
assert!(set.all_ones());
set.clear_bit(4);
assert!(!set.all_ones());
Sourcefn test_bit(&self, index: u32) -> bool
fn test_bit(&self, index: u32) -> bool
Test if the given bit is set using DefaultEndian
indexing.
Indexes which are out of bounds will wrap around in the bitset.
§Examples
use bittle::Bits;
let a: u32 = bittle::set![];
assert!(!a.test_bit(32));
let a: u32 = bittle::set![32];
assert!(a.test_bit(32));
Using a larger set:
use bittle::Bits;
let a: [u32; 2] = bittle::set![];
assert!(!a.test_bit(55));
let a: [u32; 2] = bittle::set![55];
assert!(a.test_bit(55));
Sourcefn test_bit_in<E>(&self, index: u32) -> boolwhere
E: Endian,
fn test_bit_in<E>(&self, index: u32) -> boolwhere
E: Endian,
Test if the given bit is set using custom Endian
indexing.
Indexes which are out of bounds will wrap around in the bitset.
§Examples
use bittle::{Bits, LittleEndian};
let a: u32 = bittle::set_le![];
assert!(!a.test_bit_in::<LittleEndian>(32));
let a: u32 = bittle::set_le![32];
assert!(a.test_bit_in::<LittleEndian>(32));
Using a larger set:
use bittle::{Bits, LittleEndian};
let a: [u32; 2] = bittle::set_le![];
assert!(!a.test_bit_in::<LittleEndian>(55));
let a: [u32; 2] = bittle::set_le![55];
assert!(a.test_bit_in::<LittleEndian>(55));
Sourcefn iter_ones(&self) -> Self::IterOnes<'_>
fn iter_ones(&self) -> Self::IterOnes<'_>
Construct an iterator over ones in the bit set using DefaultEndian
indexing.
Will iterate through elements from smallest to largest index.
§Examples
use bittle::Bits;
let set: u128 = bittle::set![3, 7];
assert!(set.iter_ones().eq([3, 7]));
A larger bit set:
use bittle::Bits;
let set: [u32; 4] = bittle::set![4, 67, 71, 127];
assert!(set.iter_ones().eq([4, 67, 71, 127]));
assert!(set.iter_ones().rev().eq([127, 71, 67, 4]));
Sourcefn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where
E: Endian,
fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where
E: Endian,
Construct an iterator over ones in the bit set.
Will iterate through elements from smallest to largest index.
§Examples
use bittle::{Bits, LittleEndian};
let set: u128 = bittle::set_le![3, 7];
assert!(set.iter_ones_in::<LittleEndian>().eq([3, 7]));
A larger bit set:
use bittle::{Bits, LittleEndian};
let set: [u32; 4] = bittle::set_le![4, 67, 71];
assert!(set.iter_ones_in::<LittleEndian>().eq([4, 67, 71]));
Sourcefn iter_zeros(&self) -> Self::IterZeros<'_>
fn iter_zeros(&self) -> Self::IterZeros<'_>
Construct an iterator over zeros in the bit set using DefaultEndian
indexing.
Will iterate through elements from smallest to largest index.
§Examples
use bittle::Bits;
let set: u8 = bittle::set![3, 7];
assert!(set.iter_zeros().eq([0, 1, 2, 4, 5, 6]));
A larger bit set:
use bittle::Bits;
let set: [u8; 2] = bittle::set![3, 7, 13, 14, 15];
assert!(set.iter_zeros().eq([0, 1, 2, 4, 5, 6, 8, 9, 10, 11, 12]));
assert!(set.iter_zeros().rev().eq([12, 11, 10, 9, 8, 6, 5, 4, 2, 1, 0]));
Sourcefn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where
E: Endian,
fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where
E: Endian,
Construct an iterator over zeros in the bit set.
Will iterate through elements from smallest to largest index.
§Examples
use bittle::{Bits, LittleEndian};
let set: u8 = bittle::set_le![3, 7];
assert!(set.iter_zeros_in::<LittleEndian>().eq([0, 1, 2, 4, 5, 6]));
A larger bit set:
use bittle::{Bits, LittleEndian};
let set: [u8; 2] = bittle::set_le![3, 7, 13, 14, 15];
assert!(set.iter_zeros_in::<LittleEndian>().eq([0, 1, 2, 4, 5, 6, 8, 9, 10, 11, 12]));
Provided Methods§
Sourcefn test_bit_le(&self, index: u32) -> bool
fn test_bit_le(&self, index: u32) -> bool
Test if the given bit is set using LittleEndian
indexing.
Indexes which are out of bounds will wrap around in the bitset.
§Examples
use bittle::Bits;
let a: u32 = bittle::set_le![];
assert!(!a.test_bit_le(32));
let a: u32 = bittle::set_le![32];
assert!(a.test_bit_le(32));
Using a larger set:
use bittle::Bits;
let a: [u32; 2] = bittle::set_le![];
assert!(!a.test_bit_le(55));
let a: [u32; 2] = bittle::set_le![55];
assert!(a.test_bit_le(55));
Sourcefn test_bit_be(&self, index: u32) -> bool
fn test_bit_be(&self, index: u32) -> bool
Test if the given bit is set using BigEndian
indexing.
Indexes which are out of bounds will wrap around in the bitset.
§Examples
use bittle::Bits;
let a: u32 = bittle::set_be![];
assert!(!a.test_bit_be(32));
let a: u32 = bittle::set_be![32];
assert!(a.test_bit_be(32));
Using a larger set:
use bittle::Bits;
let a: [u32; 2] = bittle::set_be![];
assert!(!a.test_bit_be(55));
let a: [u32; 2] = bittle::set_be![55];
assert!(a.test_bit_be(55));
Sourcefn iter_ones_le(&self) -> Self::IterOnesIn<'_, LittleEndian>
fn iter_ones_le(&self) -> Self::IterOnesIn<'_, LittleEndian>
Construct an iterator over ones in the bit set using LittleEndian
indexing.
Will iterate through elements from smallest to largest index.
§Examples
use bittle::Bits;
let set: u128 = bittle::set_le![3, 7];
assert!(set.iter_ones_le().eq([3, 7]));
A larger bit set:
use bittle::Bits;
let set: [u32; 4] = bittle::set_le![4, 67, 71];
assert!(set.iter_ones_le().eq([4, 67, 71]));
Sourcefn iter_ones_be(&self) -> Self::IterOnesIn<'_, BigEndian>
fn iter_ones_be(&self) -> Self::IterOnesIn<'_, BigEndian>
Construct an iterator over ones in the bit set using BigEndian
indexing.
Will iterate through elements from smallest to largest index.
§Examples
use bittle::Bits;
let set: u128 = bittle::set_be![3, 7];
assert!(set.iter_ones_be().eq([3, 7]));
A larger bit set:
use bittle::Bits;
let set: [u32; 4] = bittle::set_be![4, 67, 71];
assert!(set.iter_ones_be().eq([4, 67, 71]));
Sourcefn iter_zeros_le(&self) -> Self::IterZerosIn<'_, LittleEndian>
fn iter_zeros_le(&self) -> Self::IterZerosIn<'_, LittleEndian>
Construct an iterator over zeros in the bit set using LittleEndian
indexing.
Will iterate through elements from smallest to largest index.
§Examples
use bittle::Bits;
let set: u8 = bittle::set_le![3, 7];
assert!(set.iter_zeros_le().eq([0, 1, 2, 4, 5, 6]));
A larger bit set:
use bittle::Bits;
let set: [u8; 2] = bittle::set_le![3, 7, 13, 14, 15];
assert!(set.iter_zeros_le().eq([0, 1, 2, 4, 5, 6, 8, 9, 10, 11, 12]));
Sourcefn iter_zeros_be(&self) -> Self::IterZerosIn<'_, BigEndian>
fn iter_zeros_be(&self) -> Self::IterZerosIn<'_, BigEndian>
Construct an iterator over zeros in the bit set using BigEndian
indexing.
Will iterate through elements from smallest to largest index.
§Examples
use bittle::Bits;
let set: u8 = bittle::set_be![3, 7];
assert!(set.iter_zeros_be().eq([0, 1, 2, 4, 5, 6]));
A larger bit set:
use bittle::Bits;
let set: [u8; 2] = bittle::set_be![3, 7, 13, 14, 15];
assert!(set.iter_zeros_be().eq([0, 1, 2, 4, 5, 6, 8, 9, 10, 11, 12]));
Sourcefn join_ones_in<I, E>(&self, iter: I) -> JoinOnes<'_, Self, E, I::IntoIter>where
I: IntoIterator,
E: Endian,
fn join_ones_in<I, E>(&self, iter: I) -> JoinOnes<'_, Self, E, I::IntoIter>where
I: IntoIterator,
E: Endian,
Join this bit set with an iterator, creating an iterator that only
yields the elements which are set to ones using custom Endian
indexing.
The underlying iterator is advanced using Iterator::nth
as
appropriate.
§Examples
use bittle::{Bits, LittleEndian};
let mask: u128 = bittle::set_le![0, 1, 3];
let mut values = vec![false, false, false, false];
for value in mask.join_ones_in::<_, LittleEndian>(values.iter_mut()) {
*value = true;
}
assert_eq!(values, vec![true, true, false, true]);
Sourcefn join_ones<I>(
&self,
iter: I,
) -> JoinOnes<'_, Self, DefaultEndian, I::IntoIter>where
I: IntoIterator,
fn join_ones<I>(
&self,
iter: I,
) -> JoinOnes<'_, Self, DefaultEndian, I::IntoIter>where
I: IntoIterator,
Join this bit set with an iterator, creating an iterator that only
yields the elements which are set to ones using DefaultEndian
indexing.
The underlying iterator is advanced using Iterator::nth
as
appropriate.
§Examples
use bittle::Bits;
let mask: u128 = bittle::set![0, 1, 3];
let mut values = vec![false, false, false, false];
for value in mask.join_ones(values.iter_mut()) {
*value = true;
}
assert_eq!(values, vec![true, true, false, true]);
Sourcefn join_ones_le<I>(
&self,
iter: I,
) -> JoinOnes<'_, Self, LittleEndian, I::IntoIter>where
I: IntoIterator,
fn join_ones_le<I>(
&self,
iter: I,
) -> JoinOnes<'_, Self, LittleEndian, I::IntoIter>where
I: IntoIterator,
Join this bit set with an iterator, creating an iterator that only
yields the elements which are set to ones using LittleEndian
indexing.
The underlying iterator is advanced using Iterator::nth
as
appropriate.
§Examples
use bittle::Bits;
let mask: u8 = 0b11010000;
let mut values = vec![false, false, false, false];
for value in mask.join_ones_le(values.iter_mut()) {
*value = true;
}
assert_eq!(values, vec![true, true, false, true]);
Sourcefn join_ones_be<I>(&self, iter: I) -> JoinOnes<'_, Self, BigEndian, I::IntoIter>where
I: IntoIterator,
fn join_ones_be<I>(&self, iter: I) -> JoinOnes<'_, Self, BigEndian, I::IntoIter>where
I: IntoIterator,
Join this bit set with an iterator, creating an iterator that only
yields the elements which are set to ones using BigEndian
indexing.
The underlying iterator is advanced using Iterator::nth
as
appropriate.
§Examples
use bittle::Bits;
let mask: u8 = 0b00001011;
let mut values = vec![false, false, false, false];
for value in mask.join_ones_be(values.iter_mut()) {
*value = true;
}
assert_eq!(values, vec![true, true, false, true]);
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl Bits for i8
impl Bits for i8
type IterOnes<'a> = IterOnes<i8, BigEndian> where Self: 'a
type IterOnesIn<'a, E> = IterOnes<i8, E> where Self: 'a, E: Endian
type IterZeros<'a> = IterZeros<i8, BigEndian> where Self: 'a
type IterZerosIn<'a, E> = IterZeros<i8, E> where Self: 'a, E: Endian
fn count_ones(&self) -> u32
fn count_zeros(&self) -> u32
fn bits_capacity(&self) -> u32
fn all_zeros(&self) -> bool
fn all_ones(&self) -> bool
fn test_bit(&self, index: u32) -> bool
fn test_bit_in<E>(&self, index: u32) -> boolwhere
E: Endian,
fn iter_ones(&self) -> Self::IterOnes<'_>
fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where
E: Endian,
fn iter_zeros(&self) -> Self::IterZeros<'_>
fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where
E: Endian,
Source§impl Bits for i16
impl Bits for i16
type IterOnes<'a> = IterOnes<i16, BigEndian> where Self: 'a
type IterOnesIn<'a, E> = IterOnes<i16, E> where Self: 'a, E: Endian
type IterZeros<'a> = IterZeros<i16, BigEndian> where Self: 'a
type IterZerosIn<'a, E> = IterZeros<i16, E> where Self: 'a, E: Endian
fn count_ones(&self) -> u32
fn count_zeros(&self) -> u32
fn bits_capacity(&self) -> u32
fn all_zeros(&self) -> bool
fn all_ones(&self) -> bool
fn test_bit(&self, index: u32) -> bool
fn test_bit_in<E>(&self, index: u32) -> boolwhere
E: Endian,
fn iter_ones(&self) -> Self::IterOnes<'_>
fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where
E: Endian,
fn iter_zeros(&self) -> Self::IterZeros<'_>
fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where
E: Endian,
Source§impl Bits for i32
impl Bits for i32
type IterOnes<'a> = IterOnes<i32, BigEndian> where Self: 'a
type IterOnesIn<'a, E> = IterOnes<i32, E> where Self: 'a, E: Endian
type IterZeros<'a> = IterZeros<i32, BigEndian> where Self: 'a
type IterZerosIn<'a, E> = IterZeros<i32, E> where Self: 'a, E: Endian
fn count_ones(&self) -> u32
fn count_zeros(&self) -> u32
fn bits_capacity(&self) -> u32
fn all_zeros(&self) -> bool
fn all_ones(&self) -> bool
fn test_bit(&self, index: u32) -> bool
fn test_bit_in<E>(&self, index: u32) -> boolwhere
E: Endian,
fn iter_ones(&self) -> Self::IterOnes<'_>
fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where
E: Endian,
fn iter_zeros(&self) -> Self::IterZeros<'_>
fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where
E: Endian,
Source§impl Bits for i64
impl Bits for i64
type IterOnes<'a> = IterOnes<i64, BigEndian> where Self: 'a
type IterOnesIn<'a, E> = IterOnes<i64, E> where Self: 'a, E: Endian
type IterZeros<'a> = IterZeros<i64, BigEndian> where Self: 'a
type IterZerosIn<'a, E> = IterZeros<i64, E> where Self: 'a, E: Endian
fn count_ones(&self) -> u32
fn count_zeros(&self) -> u32
fn bits_capacity(&self) -> u32
fn all_zeros(&self) -> bool
fn all_ones(&self) -> bool
fn test_bit(&self, index: u32) -> bool
fn test_bit_in<E>(&self, index: u32) -> boolwhere
E: Endian,
fn iter_ones(&self) -> Self::IterOnes<'_>
fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where
E: Endian,
fn iter_zeros(&self) -> Self::IterZeros<'_>
fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where
E: Endian,
Source§impl Bits for i128
impl Bits for i128
type IterOnes<'a> = IterOnes<i128, BigEndian> where Self: 'a
type IterOnesIn<'a, E> = IterOnes<i128, E> where Self: 'a, E: Endian
type IterZeros<'a> = IterZeros<i128, BigEndian> where Self: 'a
type IterZerosIn<'a, E> = IterZeros<i128, E> where Self: 'a, E: Endian
fn count_ones(&self) -> u32
fn count_zeros(&self) -> u32
fn bits_capacity(&self) -> u32
fn all_zeros(&self) -> bool
fn all_ones(&self) -> bool
fn test_bit(&self, index: u32) -> bool
fn test_bit_in<E>(&self, index: u32) -> boolwhere
E: Endian,
fn iter_ones(&self) -> Self::IterOnes<'_>
fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where
E: Endian,
fn iter_zeros(&self) -> Self::IterZeros<'_>
fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where
E: Endian,
Source§impl Bits for isize
impl Bits for isize
type IterOnes<'a> = IterOnes<isize, BigEndian> where Self: 'a
type IterOnesIn<'a, E> = IterOnes<isize, E> where Self: 'a, E: Endian
type IterZeros<'a> = IterZeros<isize, BigEndian> where Self: 'a
type IterZerosIn<'a, E> = IterZeros<isize, E> where Self: 'a, E: Endian
fn count_ones(&self) -> u32
fn count_zeros(&self) -> u32
fn bits_capacity(&self) -> u32
fn all_zeros(&self) -> bool
fn all_ones(&self) -> bool
fn test_bit(&self, index: u32) -> bool
fn test_bit_in<E>(&self, index: u32) -> boolwhere
E: Endian,
fn iter_ones(&self) -> Self::IterOnes<'_>
fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where
E: Endian,
fn iter_zeros(&self) -> Self::IterZeros<'_>
fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where
E: Endian,
Source§impl Bits for u8
impl Bits for u8
type IterOnes<'a> = IterOnes<u8, BigEndian> where Self: 'a
type IterOnesIn<'a, E> = IterOnes<u8, E> where Self: 'a, E: Endian
type IterZeros<'a> = IterZeros<u8, BigEndian> where Self: 'a
type IterZerosIn<'a, E> = IterZeros<u8, E> where Self: 'a, E: Endian
fn count_ones(&self) -> u32
fn count_zeros(&self) -> u32
fn bits_capacity(&self) -> u32
fn all_zeros(&self) -> bool
fn all_ones(&self) -> bool
fn test_bit(&self, index: u32) -> bool
fn test_bit_in<E>(&self, index: u32) -> boolwhere
E: Endian,
fn iter_ones(&self) -> Self::IterOnes<'_>
fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where
E: Endian,
fn iter_zeros(&self) -> Self::IterZeros<'_>
fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where
E: Endian,
Source§impl Bits for u16
impl Bits for u16
type IterOnes<'a> = IterOnes<u16, BigEndian> where Self: 'a
type IterOnesIn<'a, E> = IterOnes<u16, E> where Self: 'a, E: Endian
type IterZeros<'a> = IterZeros<u16, BigEndian> where Self: 'a
type IterZerosIn<'a, E> = IterZeros<u16, E> where Self: 'a, E: Endian
fn count_ones(&self) -> u32
fn count_zeros(&self) -> u32
fn bits_capacity(&self) -> u32
fn all_zeros(&self) -> bool
fn all_ones(&self) -> bool
fn test_bit(&self, index: u32) -> bool
fn test_bit_in<E>(&self, index: u32) -> boolwhere
E: Endian,
fn iter_ones(&self) -> Self::IterOnes<'_>
fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where
E: Endian,
fn iter_zeros(&self) -> Self::IterZeros<'_>
fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where
E: Endian,
Source§impl Bits for u32
impl Bits for u32
type IterOnes<'a> = IterOnes<u32, BigEndian> where Self: 'a
type IterOnesIn<'a, E> = IterOnes<u32, E> where Self: 'a, E: Endian
type IterZeros<'a> = IterZeros<u32, BigEndian> where Self: 'a
type IterZerosIn<'a, E> = IterZeros<u32, E> where Self: 'a, E: Endian
fn count_ones(&self) -> u32
fn count_zeros(&self) -> u32
fn bits_capacity(&self) -> u32
fn all_zeros(&self) -> bool
fn all_ones(&self) -> bool
fn test_bit(&self, index: u32) -> bool
fn test_bit_in<E>(&self, index: u32) -> boolwhere
E: Endian,
fn iter_ones(&self) -> Self::IterOnes<'_>
fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where
E: Endian,
fn iter_zeros(&self) -> Self::IterZeros<'_>
fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where
E: Endian,
Source§impl Bits for u64
impl Bits for u64
type IterOnes<'a> = IterOnes<u64, BigEndian> where Self: 'a
type IterOnesIn<'a, E> = IterOnes<u64, E> where Self: 'a, E: Endian
type IterZeros<'a> = IterZeros<u64, BigEndian> where Self: 'a
type IterZerosIn<'a, E> = IterZeros<u64, E> where Self: 'a, E: Endian
fn count_ones(&self) -> u32
fn count_zeros(&self) -> u32
fn bits_capacity(&self) -> u32
fn all_zeros(&self) -> bool
fn all_ones(&self) -> bool
fn test_bit(&self, index: u32) -> bool
fn test_bit_in<E>(&self, index: u32) -> boolwhere
E: Endian,
fn iter_ones(&self) -> Self::IterOnes<'_>
fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where
E: Endian,
fn iter_zeros(&self) -> Self::IterZeros<'_>
fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where
E: Endian,
Source§impl Bits for u128
impl Bits for u128
type IterOnes<'a> = IterOnes<u128, BigEndian> where Self: 'a
type IterOnesIn<'a, E> = IterOnes<u128, E> where Self: 'a, E: Endian
type IterZeros<'a> = IterZeros<u128, BigEndian> where Self: 'a
type IterZerosIn<'a, E> = IterZeros<u128, E> where Self: 'a, E: Endian
fn count_ones(&self) -> u32
fn count_zeros(&self) -> u32
fn bits_capacity(&self) -> u32
fn all_zeros(&self) -> bool
fn all_ones(&self) -> bool
fn test_bit(&self, index: u32) -> bool
fn test_bit_in<E>(&self, index: u32) -> boolwhere
E: Endian,
fn iter_ones(&self) -> Self::IterOnes<'_>
fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where
E: Endian,
fn iter_zeros(&self) -> Self::IterZeros<'_>
fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where
E: Endian,
Source§impl Bits for usize
impl Bits for usize
type IterOnes<'a> = IterOnes<usize, BigEndian> where Self: 'a
type IterOnesIn<'a, E> = IterOnes<usize, E> where Self: 'a, E: Endian
type IterZeros<'a> = IterZeros<usize, BigEndian> where Self: 'a
type IterZerosIn<'a, E> = IterZeros<usize, E> where Self: 'a, E: Endian
fn count_ones(&self) -> u32
fn count_zeros(&self) -> u32
fn bits_capacity(&self) -> u32
fn all_zeros(&self) -> bool
fn all_ones(&self) -> bool
fn test_bit(&self, index: u32) -> bool
fn test_bit_in<E>(&self, index: u32) -> boolwhere
E: Endian,
fn iter_ones(&self) -> Self::IterOnes<'_>
fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where
E: Endian,
fn iter_zeros(&self) -> Self::IterZeros<'_>
fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where
E: Endian,
Source§impl<T> Bits for &T
impl<T> Bits for &T
type IterOnes<'a> = <T as Bits>::IterOnes<'a> where Self: 'a
type IterOnesIn<'a, E> = <T as Bits>::IterOnesIn<'a, E> where Self: 'a, E: Endian
type IterZeros<'a> = <T as Bits>::IterZeros<'a> where Self: 'a
type IterZerosIn<'a, E> = <T as Bits>::IterZerosIn<'a, E> where Self: 'a, E: Endian
fn count_ones(&self) -> u32
fn count_zeros(&self) -> u32
fn bits_capacity(&self) -> u32
fn all_zeros(&self) -> bool
fn all_ones(&self) -> bool
fn test_bit(&self, index: u32) -> bool
fn test_bit_in<E>(&self, index: u32) -> boolwhere
E: Endian,
fn iter_ones(&self) -> Self::IterOnes<'_>
fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where
E: Endian,
fn iter_zeros(&self) -> Self::IterZeros<'_>
fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where
E: Endian,
Source§impl<T> Bits for &mut T
impl<T> Bits for &mut T
type IterOnesIn<'a, E> = <T as Bits>::IterOnesIn<'a, E> where Self: 'a, E: Endian
type IterOnes<'a> = <T as Bits>::IterOnes<'a> where Self: 'a
type IterZerosIn<'a, E> = <T as Bits>::IterZerosIn<'a, E> where Self: 'a, E: Endian
type IterZeros<'a> = <T as Bits>::IterZeros<'a> where Self: 'a
fn count_ones(&self) -> u32
fn count_zeros(&self) -> u32
fn bits_capacity(&self) -> u32
fn all_zeros(&self) -> bool
fn all_ones(&self) -> bool
fn test_bit(&self, index: u32) -> bool
fn test_bit_in<E>(&self, index: u32) -> boolwhere
E: Endian,
fn iter_ones(&self) -> Self::IterOnes<'_>
fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where
E: Endian,
fn iter_zeros(&self) -> Self::IterZeros<'_>
fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where
E: Endian,
Source§impl<T> Bits for [T]where
T: BitsOwned,
impl<T> Bits for [T]where
T: BitsOwned,
Source§fn count_ones(&self) -> u32
fn count_ones(&self) -> u32
Count the number of ones in the slice.
§Examples
use bittle::Bits;
let a: [u8; 2] = bittle::set![4, 11, 14];
let a = a.as_slice();
assert_eq!(a.count_ones(), 3);
Source§fn count_zeros(&self) -> u32
fn count_zeros(&self) -> u32
Count the number of zeros in the slice.
§Examples
use bittle::Bits;
let a: [u8; 2] = bittle::set![4, 11, 14];
let a = a.as_slice();
assert_eq!(a.count_zeros(), 13);
Source§fn bits_capacity(&self) -> u32
fn bits_capacity(&self) -> u32
Get the capacity of the slice.
The capacity of a slice is determined by its length.
§Examples
use bittle::Bits;
let a: [u8; 4] = bittle::set![4, 11, 14];
let a = &a[..2];
assert_eq!(a.bits_capacity(), 16);
Source§fn all_zeros(&self) -> bool
fn all_zeros(&self) -> bool
Test if the slice is all zeros.
§Examples
use bittle::Bits;
let a: [u8; 2] = bittle::set![];
let a = a.as_slice();
assert!(a.all_zeros());
let a: [u8; 2] = bittle::set![4, 11, 14];
let a = a.as_slice();
assert!(!a.all_zeros());
Source§fn all_ones(&self) -> bool
fn all_ones(&self) -> bool
Test if the slice is all ones.
§Examples
use bittle::Bits;
let a: [u8; 2] = bittle::set![0..16];
let a = a.as_slice();
assert!(a.all_ones());
let a: [u8; 2] = bittle::set![4, 11, 14];
let a = a.as_slice();
assert!(!a.all_ones());
Source§fn test_bit(&self, index: u32) -> bool
fn test_bit(&self, index: u32) -> bool
Test if the given bit is set in the slice.
§Examples
use bittle::Bits;
let mut a: [u8; 2] = bittle::set![4, 11, 14];
let a: &[u8] = a.as_slice();
assert!(a.test_bit(4));
Source§fn test_bit_in<E>(&self, index: u32) -> boolwhere
E: Endian,
fn test_bit_in<E>(&self, index: u32) -> boolwhere
E: Endian,
Test if the given bit is set in the slice.
§Examples
use bittle::{Bits, BigEndian};
let mut a: [u8; 2] = bittle::set_be![4, 11, 14];
let a: &[u8] = a.as_slice();
assert!(a.test_bit_in::<BigEndian>(4));
Source§fn iter_ones(&self) -> Self::IterOnes<'_>
fn iter_ones(&self) -> Self::IterOnes<'_>
Iterates over all ones in the slice using DefaultEndian
indexing.
§Examples
use bittle::Bits;
let mut a: [u8; 2] = bittle::set![4, 11, 14];
let a: &[u8] = a.as_slice();
assert!(a.iter_ones().eq([4, 11, 14]));
let a: &[u8] = &[];
assert!(a.iter_ones().eq([]));
Source§fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where
E: Endian,
fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where
E: Endian,
Source§fn iter_zeros(&self) -> Self::IterZeros<'_>
fn iter_zeros(&self) -> Self::IterZeros<'_>
Iterates over all zeros in the slice using DefaultEndian
indexing.
§Examples
use bittle::Bits;
let mut a: [u8; 2] = bittle::set![4, 11, 14];
let a: &[u8] = a.as_slice();
assert!(a.iter_zeros().eq([0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 12, 13, 15]));
let a: &[u8] = &[];
assert!(a.iter_zeros().eq([]));
Source§fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where
E: Endian,
fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where
E: Endian,
type IterOnes<'a> = IterOnes<'a, T, BigEndian> where Self: 'a
type IterOnesIn<'a, E> = IterOnes<'a, T, E> where Self: 'a, E: Endian
type IterZeros<'a> = IterZeros<'a, T, BigEndian> where Self: 'a
type IterZerosIn<'a, E> = IterZeros<'a, T, E> where Self: 'a, E: Endian
Source§impl<T, const N: usize> Bits for [T; N]
impl<T, const N: usize> Bits for [T; N]
Source§fn count_ones(&self) -> u32
fn count_ones(&self) -> u32
Count the number of ones in the array.
§Examples
use bittle::Bits;
let a: [u8; 2] = bittle::set![4, 11, 14];
assert_eq!(a.count_ones(), 3);
Source§fn count_zeros(&self) -> u32
fn count_zeros(&self) -> u32
Count the number of zeros in the array.
§Examples
use bittle::Bits;
let a: [u8; 2] = bittle::set![4, 11, 14];
assert_eq!(a.count_zeros(), 13);
Source§fn bits_capacity(&self) -> u32
fn bits_capacity(&self) -> u32
Get the capacity of the array.
The capacity of a array is determined by its length.
§Examples
use bittle::Bits;
let a: [u8; 4] = bittle::set![4, 11, 14];
assert_eq!(a.bits_capacity(), 32);
Also note that the capacity of an array is known at compile-time through
BitsOwned::BITS
:
use bittle::BitsOwned;
const CAP: u32 = <[u8; 4]>::BITS;
assert_eq!(CAP, 32);
Source§fn all_zeros(&self) -> bool
fn all_zeros(&self) -> bool
Test if the array is all zeros.
§Examples
use bittle::Bits;
let a: [u8; 2] = bittle::set![];
assert!(a.all_zeros());
let a: [u8; 2] = bittle::set![4, 11, 14];
assert!(!a.all_zeros());
Source§fn all_ones(&self) -> bool
fn all_ones(&self) -> bool
Test if the array is all ones.
§Examples
use bittle::Bits;
let a: [u8; 2] = bittle::set![0..16];
assert!(a.all_ones());
let a: [u8; 2] = bittle::set![4, 11, 14];
assert!(!a.all_ones());
Source§fn test_bit(&self, index: u32) -> bool
fn test_bit(&self, index: u32) -> bool
Test if the given bit is set in the array.
§Examples
use bittle::Bits;
let mut a: [u8; 2] = bittle::set![4, 11, 14];
assert!(a.test_bit(4));
Source§fn test_bit_in<E>(&self, index: u32) -> boolwhere
E: Endian,
fn test_bit_in<E>(&self, index: u32) -> boolwhere
E: Endian,
Test if the given bit is set in the array.
§Examples
use bittle::{Bits, BigEndian};
let mut a: [u8; 2] = bittle::set_be![4, 11, 14];
assert!(a.test_bit_in::<BigEndian>(4));
Source§fn iter_ones(&self) -> Self::IterOnes<'_>
fn iter_ones(&self) -> Self::IterOnes<'_>
Iterates over all ones in the array using DefaultEndian
indexing.
§Examples
use bittle::Bits;
let mut a: [u8; 2] = bittle::set![4, 11, 14];
assert!(a.iter_ones().eq([4, 11, 14]));
let a: [u8; 0] = [];
assert!(a.iter_ones().eq([]));
Source§fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where
E: Endian,
fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where
E: Endian,
Source§fn iter_zeros(&self) -> Self::IterZeros<'_>
fn iter_zeros(&self) -> Self::IterZeros<'_>
Iterates over all zeros in the array using DefaultEndian
indexing.
§Examples
use bittle::Bits;
let mut a: [u8; 2] = bittle::set![4, 11, 14];
assert!(a.iter_zeros().eq([0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 12, 13, 15]));
let a: [u8; 0] = [];
assert!(a.iter_zeros().eq([]));