| 156 | } |
| 157 | |
| 158 | fn nth_back(&mut self, n: usize) -> Option<Self::Item> { |
| 159 | // Check if we can advance to the desired offset. |
| 160 | // When n is 0 it means we want the next_back() value |
| 161 | // and when n is 1 we want the next_back().next_back() value |
| 162 | // so subtracting n to the current offset and not n - 1 |
| 163 | match self.end_offset.checked_sub(n) { |
| 164 | // Yes, and still within bounds |
| 165 | Some(new_offset) if self.current_offset < new_offset => { |
| 166 | self.end_offset = new_offset; |
| 167 | } |
| 168 | |
| 169 | // Either underflow or would exceed current_offset |
| 170 | _ => { |
| 171 | self.current_offset = self.end_offset; |
| 172 | return None; |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | self.next_back() |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | /// Iterator of contiguous ranges of set bits within a provided packed bitmask |