use fixed_bit_string::FixedBitString;
#[derive(Clone,Debug)]
pub struct Iter<B> {
next: Option<B>,
prefix: usize,
}
impl<B: FixedBitString> Iter<B> {
#[doc(hidden)]
pub fn new(start: B, prefix: usize) -> Self {
Iter{
next: Some(start),
prefix: prefix,
}
}
}
impl<B: FixedBitString+Clone> Iterator for Iter<B> {
type Item = B;
fn next(&mut self) -> Option<Self::Item> {
let mut overflow = false;
let result = match self.next {
None => None,
Some(ref mut next) => {
let result = Some(next.clone());
overflow = next.inc(self.prefix);
result
}
};
if overflow {
self.next = None;
}
result
}
}