pub trait BitIterator {
// Required methods
fn bit_iter(&self) -> impl DoubleEndedIterator<Item = bool>;
fn bit_chunks<T>(&self, n: usize) -> impl Iterator<Item = T>
where T: TryFrom<u64> + Default;
}Expand description
Bits iterator implementation on [u8]
Required Methods§
Sourcefn bit_iter(&self) -> impl DoubleEndedIterator<Item = bool>
fn bit_iter(&self) -> impl DoubleEndedIterator<Item = bool>
Iterator bits
§Examples
assert_eq!(
[0b1111_0000_u8].bit_iter().collect::<Vec<bool>>(),
vec![true, true, true, true, false, false, false, false]
);Sourcefn bit_chunks<T>(&self, n: usize) -> impl Iterator<Item = T>
fn bit_chunks<T>(&self, n: usize) -> impl Iterator<Item = T>
Returns the bits in the buffer grouped by n
§Parameters
T: the type to contains the grouped bitsn: the number of bits to group- 1 <= n <= T::BITS <= 32
§Examples
assert_eq!(
vec![0b1111_1111, 0b1111_1111].bit_chunks(6).collect::<Vec<u8>>(),
vec![0b11_1111, 0b11_1111, 0b11_1100]
);
assert_eq!(
vec![0b1111_1111; 3].bit_chunks(11).collect::<Vec<u16>>(),
vec![0b111_1111_1111, 0b111_1111_1111, 0b110_0000_0000]
);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.