bitstring/fixed_bit_string/
iter.rs1use super::traits::FixedBitString;
2
3#[derive(Clone, Debug)]
10pub struct Iter<B> {
11 next: Option<B>,
12 prefix: usize,
13}
14
15impl<B: FixedBitString> Iter<B> {
16 #[doc(hidden)]
17 pub fn new(start: B, prefix: usize) -> Self {
19 Iter {
20 next: Some(start),
21 prefix,
22 }
23 }
24}
25
26impl<B: FixedBitString + Clone> Iterator for Iter<B> {
27 type Item = B;
28
29 fn next(&mut self) -> Option<Self::Item> {
30 let mut overflow = false;
31 let result = match self.next {
32 None => None,
33 Some(ref mut next) => {
34 let result = Some(next.clone());
35 overflow = next.inc(self.prefix);
36 result
37 },
38 };
39 if overflow {
40 self.next = None;
41 }
42 result
43 }
44}