pub trait AsBits {
type Iter: Iterator;
// Required method
fn as_bits(self) -> Bits<Self::Iter> ⓘ;
}Expand description
This trait takes a generator of integers and transforms it into a stream of
the bits that compose each of them. This crate already implements it for all
integer types, so it only needs to be brought into scope via
use bitsreader::AsBits.
If it were to be implemented by some custom numeric type, the trait One must be implemented for it.
Required Associated Types§
Required Methods§
Sourcefn as_bits(self) -> Bits<Self::Iter> ⓘ
fn as_bits(self) -> Bits<Self::Iter> ⓘ
Transforms an iterator of integers into a stream of the bits that compose each of them.
§Examples
use bitsreader::AsBits;
let mut bits = [0b1011_0101u8, 0b0100_1110].iter().as_bits();
assert_eq!(bits.next(), Some(1));
assert_eq!(bits.next(), Some(0));
assert_eq!(bits.nth(6), Some(0)); // The next byte
assert_eq!(bits.nth(6), Some(0)); // The last bit
assert_eq!(bits.next(), None);
assert_eq!(bits.next_back(), Some(0)); // It's also double-ended!