Skip to main content

omena_reactive/
value.rs

1use std::collections::{BTreeMap, BTreeSet};
2
3/// Values carried by the static graph.
4#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
5#[non_exhaustive]
6pub enum ReactiveValueV0 {
7    Unit,
8    Bool(bool),
9    Counter(u64),
10    Text(String),
11    StringSet(BTreeSet<String>),
12    TextMap(BTreeMap<String, String>),
13    Tuple(Vec<Self>),
14    Digest([u8; 32]),
15}
16
17/// A node-local failure. Unavailability propagates as data and never poisons
18/// unrelated nodes or the graph itself.
19#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
20#[non_exhaustive]
21pub struct ReactiveUnavailableV0 {
22    pub code: String,
23    pub detail: String,
24}
25
26impl ReactiveUnavailableV0 {
27    pub fn new(code: impl Into<String>, detail: impl Into<String>) -> Self {
28        Self {
29            code: code.into(),
30            detail: detail.into(),
31        }
32    }
33
34    pub(crate) fn pending() -> Self {
35        Self::new(
36            "pendingInitialComputation",
37            "the node has not completed its first necessary computation",
38        )
39    }
40}
41
42/// The complete state of one node.
43#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
44#[non_exhaustive]
45pub enum ReactiveStateV0 {
46    Available(ReactiveValueV0),
47    Unavailable(ReactiveUnavailableV0),
48}
49
50impl ReactiveStateV0 {
51    pub fn available(value: ReactiveValueV0) -> Self {
52        Self::Available(value)
53    }
54
55    pub fn unavailable(code: impl Into<String>, detail: impl Into<String>) -> Self {
56        Self::Unavailable(ReactiveUnavailableV0::new(code, detail))
57    }
58
59    pub(crate) fn pending() -> Self {
60        Self::Unavailable(ReactiveUnavailableV0::pending())
61    }
62}