use crate::binary::Binary;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Zeros<T: Binary> {
n: T,
}
impl<T: Binary> Zeros<T> {
pub const fn new(n: T) -> Self {
Self { n }
}
}
impl<T: Binary> Iterator for Zeros<T> {
type Item = T;
fn next(&mut self) -> Option<Self::Item> {
self.n.has_zero().then(|| {
let b = self.n.lowest_zero();
self.n ^= b;
b
})
}
}
impl<T: Binary> DoubleEndedIterator for Zeros<T> {
fn next_back(&mut self) -> Option<Self::Item> {
self.n.has_zero().then(|| {
let b = self.n.highest_zero();
self.n ^= b;
b
})
}
}