Skip to main content

orbit_rs/ring/cursor/
state.rs

1/// Caller-owned position in a ring walk.
2///
3/// The cursor stores the next counter a reader should attempt. Different
4/// subscribers keep independent cursors over the same ring.
5#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
6pub struct RingCursor {
7    next_counter: u64,
8}
9
10impl RingCursor {
11    /// Start at counter 0 and replay whatever ring history is still
12    /// available.
13    pub const fn from_start() -> Self {
14        Self { next_counter: 0 }
15    }
16
17    /// Start from a known next counter.
18    pub const fn from_counter(next_counter: u64) -> Self {
19        Self { next_counter }
20    }
21
22    /// The next counter this cursor will read.
23    pub const fn next_counter(self) -> u64 {
24        self.next_counter
25    }
26
27    pub(crate) fn set_next_counter(&mut self, next_counter: u64) {
28        self.next_counter = next_counter;
29    }
30}