sim_incremental_core/
observation.rs1use crate::ValueFingerprint;
4
5#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
7pub struct Revision(u64);
8
9impl Revision {
10 pub const ZERO: Self = Self(0);
12
13 #[must_use]
15 pub const fn new(value: u64) -> Self {
16 Self(value)
17 }
18
19 #[must_use]
21 pub const fn get(self) -> u64 {
22 self.0
23 }
24}
25
26#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
28pub enum ObservationKind {
29 Read,
31 Missing,
33 Listing,
35 Policy,
37 Epoch,
39 Custom(&'static str),
41}
42
43#[derive(Clone, Debug, Eq, Hash, PartialEq)]
45pub struct Observation<K> {
46 key: K,
47 kind: ObservationKind,
48 revision: Revision,
49 fingerprint: Option<ValueFingerprint>,
50}
51
52impl<K> Observation<K> {
53 #[must_use]
56 pub fn new(
57 key: K,
58 kind: ObservationKind,
59 revision: Revision,
60 fingerprint: Option<ValueFingerprint>,
61 ) -> Self {
62 Self {
63 key,
64 kind,
65 revision,
66 fingerprint,
67 }
68 }
69
70 #[must_use]
72 pub fn read(key: K, revision: Revision, fingerprint: ValueFingerprint) -> Self {
73 Self::new(key, ObservationKind::Read, revision, Some(fingerprint))
74 }
75
76 #[must_use]
78 pub fn key(&self) -> &K {
79 &self.key
80 }
81
82 #[must_use]
84 pub fn kind(&self) -> &ObservationKind {
85 &self.kind
86 }
87
88 #[must_use]
90 pub fn revision(&self) -> Revision {
91 self.revision
92 }
93
94 #[must_use]
96 pub fn fingerprint(&self) -> Option<ValueFingerprint> {
97 self.fingerprint
98 }
99}