Skip to main content

saya_types/contract/
slot_state.rs

1//! The persisted lifecycle states a knowledge slot's value can be in.
2
3use serde::{Deserialize, Serialize};
4
5/// The three persisted states a knowledge slot's value can be in. Distinct
6/// from `ClaimStatus`, which is still in use and whose `Contradicted` variant
7/// is load-bearing in `saya-store`'s transition rules; this adds the new
8/// vocabulary beside it.
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
10#[serde(rename_all = "snake_case")]
11#[non_exhaustive]
12pub enum KnowledgeState {
13    Pending,
14    Active,
15    Dismissed,
16}
17
18impl KnowledgeState {
19    pub const fn as_str(self) -> &'static str {
20        match self {
21            Self::Pending => "pending",
22            Self::Active => "active",
23            Self::Dismissed => "dismissed",
24        }
25    }
26
27    pub fn parse(value: &str) -> Option<Self> {
28        match value {
29            "pending" => Some(Self::Pending),
30            "active" => Some(Self::Active),
31            "dismissed" => Some(Self::Dismissed),
32            _ => None,
33        }
34    }
35}