Skip to main content

forge_server/
unseen.rs

1//! The green diamond: a turn that finished on a session this page has not
2//! shown since.
3
4use std::collections::HashSet;
5
6use forge_primitives::SessionSlot;
7
8/// Which sessions have finished a turn since this view last showed them.
9///
10/// Viewer-relative by nature - whether a completion is unseen depends on
11/// who is looking, and two views can disagree about the same slot and both
12/// be right - so it is held here rather than on the core.
13#[derive(Default, Clone)]
14pub struct Unseen {
15    unseen: HashSet<SessionSlot>,
16}
17
18impl Unseen {
19    pub fn new() -> Self {
20        Self::default()
21    }
22
23    /// A turn finished on `slot`. Marking an already-unseen session is the
24    /// same as marking it once.
25    pub fn mark_completed(&mut self, slot: &SessionSlot) {
26        self.unseen.insert(slot.clone());
27    }
28
29    /// This view has shown `slot`, so nothing about it is unseen.
30    pub fn clear(&mut self, slot: &SessionSlot) {
31        self.unseen.remove(slot);
32    }
33
34    pub fn is_unseen(&self, slot: &SessionSlot) -> bool {
35        self.unseen.contains(slot)
36    }
37}