tree_table/types/cycling_counter.rs
1#[derive(Debug, Clone)]
2pub struct CyclingCounter {
3 current: usize,
4}
5
6impl CyclingCounter {
7 /// Creates a new `CyclingCounter` starting at 0.
8 pub fn new() -> Self {
9 CyclingCounter { current: 0 }
10 }
11}
12
13impl Iterator for CyclingCounter {
14 type Item = usize;
15
16 /// Returns the next `usize` value, cycling back to 0 after `usize::MAX`.
17 fn next(&mut self) -> Option<Self::Item> {
18 let current = self.current;
19 self.current = self.current.wrapping_add(1);
20 Some(current)
21 }
22}