Skip to main content

qualia_core_db/net/qdnf/resolve/qsr/
outcome.rs

1//! Tagged QSR lookup outcomes. Authenticated lookup never returns bool.
2
3/// Result of an exact QSR lookup against a named snapshot or cover.
4///
5/// `Found` carries a bounded candidate count. Targets are copied into the
6/// caller buffer by the traversal; this tag is not a negative or positive
7/// existence claim by itself without that copy.
8#[repr(u8)]
9#[derive(Clone, Copy, Debug, PartialEq, Eq)]
10pub enum QsrOutcome {
11    /// Authenticated exact match. `count` is the number of targets staged.
12    Found { count: u8 } = 1,
13    /// Named snapshot has no matching key under a cover that includes the prefix.
14    EmptyInSnapshot = 2,
15    /// Bounded progress; caller must continue with remaining budget.
16    NeedContinuation = 3,
17    /// Cover or evidence does not speak to this prefix. Not a negative answer.
18    Incomplete = 4,
19    /// Required generation does not match the snapshot (unless Generation(0)).
20    Stale = 5,
21    /// Conflicting values for the same full key in the snapshot.
22    Conflict = 6,
23}
24
25impl QsrOutcome {
26    #[inline]
27    /// `QsrOutcome::found_count`.
28    pub const fn found_count(self) -> Option<u8> {
29        match self {
30            Self::Found { count } => Some(count),
31            _ => None,
32        }
33    }
34}
35
36#[cfg(test)]
37mod tests {
38    use super::*;
39
40    #[test]
41    fn found_carries_count() {
42        assert_eq!(QsrOutcome::Found { count: 1 }.found_count(), Some(1));
43        assert_eq!(QsrOutcome::EmptyInSnapshot.found_count(), None);
44    }
45
46    #[test]
47    fn outcomes_are_distinct() {
48        assert_ne!(QsrOutcome::Found { count: 1 }, QsrOutcome::EmptyInSnapshot);
49        assert_ne!(QsrOutcome::EmptyInSnapshot, QsrOutcome::Incomplete);
50        assert_ne!(QsrOutcome::Stale, QsrOutcome::Conflict);
51    }
52}