Coverage Report

Created: 2026-01-17 07:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/sharded-slab-0.1.7/src/iter.rs
Line
Count
Source
1
use std::{iter::FusedIterator, slice};
2
3
use crate::{cfg, page, shard};
4
5
/// An exclusive fused iterator over the items in a [`Slab`](crate::Slab).
6
#[must_use = "iterators are lazy and do nothing unless consumed"]
7
#[derive(Debug)]
8
pub struct UniqueIter<'a, T, C: cfg::Config> {
9
    pub(super) shards: shard::IterMut<'a, Option<T>, C>,
10
    pub(super) pages: slice::Iter<'a, page::Shared<Option<T>, C>>,
11
    pub(super) slots: Option<page::Iter<'a, T, C>>,
12
}
13
14
impl<'a, T, C: cfg::Config> Iterator for UniqueIter<'a, T, C> {
15
    type Item = &'a T;
16
17
0
    fn next(&mut self) -> Option<Self::Item> {
18
0
        test_println!("UniqueIter::next");
19
        loop {
20
0
            test_println!("-> try next slot");
21
0
            if let Some(item) = self.slots.as_mut().and_then(|slots| slots.next()) {
22
0
                test_println!("-> found an item!");
23
0
                return Some(item);
24
0
            }
25
26
0
            test_println!("-> try next page");
27
0
            if let Some(page) = self.pages.next() {
28
0
                test_println!("-> found another page");
29
0
                self.slots = page.iter();
30
0
                continue;
31
0
            }
32
33
0
            test_println!("-> try next shard");
34
0
            if let Some(shard) = self.shards.next() {
35
0
                test_println!("-> found another shard");
36
0
                self.pages = shard.iter();
37
            } else {
38
0
                test_println!("-> all done!");
39
0
                return None;
40
            }
41
        }
42
0
    }
43
}
44
45
impl<T, C: cfg::Config> FusedIterator for UniqueIter<'_, T, C> {}