bitref 0.0.0

Reference types for bitstrings with bit-level slicing support
Documentation
//! Iterator over bits.

use crate::BitSlice;
use core::iter::Iterator;

/// Iterator over the bits of a [`BitSlice`].
// TODO(tarcieri): `ExactSizeIterator`, `DoubleEndedIterator`, `FusedIterator`, etc.
#[derive(Clone, Debug)]
pub struct Iter<'a> {
    slice: &'a BitSlice,
}

impl<'a> Iter<'a> {
    /// Create a new iterator over a `BitSlice`.
    pub fn new(slice: &'a BitSlice) -> Self {
        Self { slice }
    }
}

impl<'a> Iterator for Iter<'a> {
    type Item = bool;

    fn next(&mut self) -> Option<bool> {
        match self.slice.split_first() {
            Some((bit, rest)) => {
                self.slice = rest;
                Some(bit)
            }
            None => None,
        }
    }
}