zaun_community_protocol/client/cursors/
cursor.rs1use std::collections::BTreeMap;
4
5use crate::envelope::EventEnvelope;
6use crate::event::Event;
7
8#[derive(Debug, Clone)]
11pub(in crate::client) struct Held {
12 pub(in crate::client) envelope: EventEnvelope,
13 pub(in crate::client) event: Option<Event>,
14}
15
16#[derive(Debug, Clone, Default)]
18pub struct Cursor {
19 pub(super) applied: u64,
20 pub(super) held: BTreeMap<u64, Held>,
21}
22
23impl Cursor {
24 #[must_use]
26 pub const fn applied(&self) -> u64 {
27 self.applied
28 }
29
30 #[must_use]
32 pub fn held(&self) -> usize {
33 self.held.len()
34 }
35
36 pub(super) fn release(&mut self) -> Vec<Held> {
38 self.held = self.held.split_off(&self.applied.saturating_add(1));
39 let mut ready = Vec::new();
40 while let Some(next) = self.held.remove(&self.applied.saturating_add(1)) {
41 self.applied = self.applied.saturating_add(1);
42 ready.push(next);
43 }
44 ready
45 }
46}