zrx_stream/stream/barrier/advance.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//! Barrier advancement.
27
28use zrx_scheduler::{Id, Key};
29use zrx_store::stash::Items;
30use zrx_store::Stash;
31
32mod iter;
33
34pub use iter::Iter;
35
36// ----------------------------------------------------------------------------
37// Structs
38// ----------------------------------------------------------------------------
39
40/// Barrier advancement.
41#[derive(Debug)]
42pub struct Advance<'a, I> {
43 /// Barrier scope for identification.
44 key: &'a Key<I>,
45 /// Contained scopes.
46 items: &'a Items,
47 /// All known scopes.
48 scopes: &'a Stash<Key<I>, Items>,
49}
50
51// ----------------------------------------------------------------------------
52// Implementations
53// ----------------------------------------------------------------------------
54
55impl<'a, I> Advance<'a, I> {
56 /// Converts the barrier advancement into an event.
57 #[must_use]
58 pub fn new(
59 key: &'a Key<I>, items: &'a Items, scopes: &'a Stash<Key<I>, Items>,
60 ) -> Self {
61 Self { key, items, scopes }
62 }
63}
64
65#[allow(clippy::must_use_candidate)]
66impl<I> Advance<'_, I> {
67 /// Returns a reference to the scope.
68 #[inline]
69 pub fn scope(&self) -> &Key<I> {
70 self.key
71 }
72}
73
74// ----------------------------------------------------------------------------
75// Trait implementations
76// ----------------------------------------------------------------------------
77
78impl<'a, I> IntoIterator for &'a Advance<'a, I>
79where
80 I: Id,
81{
82 type Item = &'a Key<I>;
83 type IntoIter = Iter<'a, I>;
84
85 /// Creates a consuming iterator over the barrier advancement.
86 #[inline]
87 fn into_iter(self) -> Self::IntoIter {
88 self.iter()
89 }
90}