Skip to main content

zrx_stream/stream/barrier/advance/
iter.rs

1// Copyright (c) 2025-2026 Zensical and contributors
2
3// SPDX-License-Identifier: MIT
4// All contributions are certified under the DCO
5
6// Permission is hereby granted, free of charge, to any person obtaining a copy
7// of this software and associated documentation files (the "Software"), to
8// deal in the Software without restriction, including without limitation the
9// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10// sell copies of the Software, and to permit persons to whom the Software is
11// furnished to do so, subject to the following conditions:
12
13// The above copyright notice and this permission notice shall be included in
14// all copies or substantial portions of the Software.
15
16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22// IN THE SOFTWARE.
23
24// ----------------------------------------------------------------------------
25
26//! Iterator implementation for [`Advance`].
27
28use zrx_scheduler::{Id, Key};
29use zrx_store::Stash;
30use zrx_store::stash::slab::map;
31
32use crate::stream::barrier::Slots;
33
34use super::Advance;
35
36// ----------------------------------------------------------------------------
37// Structs
38// ----------------------------------------------------------------------------
39
40/// Iterator for [`Advance`].
41pub struct Iter<'a, I> {
42    /// Inner iterator.
43    inner: map::Iter<'a, zrx_store::stash::Slot, ()>,
44    /// All known scopes.
45    stash: &'a Stash<Key<I>, Slots>,
46}
47
48// ----------------------------------------------------------------------------
49// Implementations
50// ----------------------------------------------------------------------------
51
52impl<'a, I> Advance<'a, I>
53where
54    I: Id,
55{
56    /// Creates an iterator over the barrier advancement.
57    #[inline]
58    #[must_use]
59    pub fn iter(&self) -> Iter<'a, I> {
60        Iter {
61            inner: self.slots.iter(),
62            stash: self.scopes,
63        }
64    }
65}
66
67// ----------------------------------------------------------------------------
68// Trait implementations
69// ----------------------------------------------------------------------------
70
71impl<'a, I> Iterator for Iter<'a, I>
72where
73    I: Id,
74{
75    type Item = &'a Key<I>;
76
77    /// Returns the next scope.
78    #[inline]
79    fn next(&mut self) -> Option<Self::Item> {
80        self.inner
81            .next()
82            .and_then(|(slot, ())| self.stash.key(*slot))
83    }
84}