AsBits

Trait AsBits 

Source
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§

Source

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!

Implementors§

Source§

impl<'a, I, T, S, B> AsBits for I
where I: Iterator<Item = &'a T> + DoubleEndedIterator + Clone, T: 'a + Copy + Default + Shr<usize, Output = S>, S: BitAnd<S, Output = B> + One, B: PartialEq + One,