Skip to main content

stoa_core/
kind.rs

1//! Enums for page `kind` and `status` (ARCHITECTURE §2).
2
3use serde::{Deserialize, Serialize};
4
5/// Wiki page kind (ARCHITECTURE §2). Mirrors the directory layout under
6/// `wiki/{entities,concepts,synthesis}/`.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
8#[serde(rename_all = "lowercase")]
9pub enum Kind {
10    /// A real thing with identity over time (person, project, library, …).
11    Entity,
12    /// An abstract topic or pattern.
13    Concept,
14    /// A cross-cutting essay built from entities, concepts, and raw sources.
15    Synthesis,
16}
17
18impl Kind {
19    /// Canonical lowercase string for the kind (matches the YAML form).
20    #[must_use]
21    pub fn as_str(self) -> &'static str {
22        match self {
23            Self::Entity => "entity",
24            Self::Concept => "concept",
25            Self::Synthesis => "synthesis",
26        }
27    }
28
29    /// Default allow-list — used when `STOA.md` doesn't override.
30    #[must_use]
31    pub fn defaults() -> &'static [Self] {
32        &[Self::Entity, Self::Concept, Self::Synthesis]
33    }
34}
35
36impl std::fmt::Display for Kind {
37    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38        f.write_str(self.as_str())
39    }
40}
41
42/// Page lifecycle status (ARCHITECTURE §2 + §4.1).
43#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
44#[serde(rename_all = "lowercase")]
45pub enum Status {
46    /// Currently authoritative.
47    Active,
48    /// Replaced by a newer page (see `supersedes:` link).
49    Superseded,
50    /// Heuristically flagged as no-longer-fresh (ARCHITECTURE §4.2).
51    Stale,
52    /// Hard-retired by user/agent.
53    Deprecated,
54}
55
56impl Status {
57    /// Canonical lowercase string for the status.
58    #[must_use]
59    pub fn as_str(self) -> &'static str {
60        match self {
61            Self::Active => "active",
62            Self::Superseded => "superseded",
63            Self::Stale => "stale",
64            Self::Deprecated => "deprecated",
65        }
66    }
67
68    /// Default allow-list (ARCHITECTURE §2).
69    #[must_use]
70    pub fn defaults() -> &'static [Self] {
71        &[
72            Self::Active,
73            Self::Superseded,
74            Self::Stale,
75            Self::Deprecated,
76        ]
77    }
78}
79
80impl std::fmt::Display for Status {
81    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
82        f.write_str(self.as_str())
83    }
84}