#[derive(Debug)] pub struct BitIterator { t: E, n: usize, } impl> BitIterator { pub fn new(t: E) -> Self { let n = t.as_ref().len() * 64; BitIterator { t, n } } } impl> Iterator for BitIterator { type Item = bool; fn next(&mut self) -> Option { if self.n == 0 { None } else { self.n -= 1; let part = self.n / 64; let bit = self.n - (64 * part); Some(self.t.as_ref()[part] & (1 << bit) > 0) } } }