Skip to main content

weavatrix_refactor_plan/
code.rs

1use serde::{Deserialize, Serialize};
2use std::fmt;
3
4macro_rules! open_code {
5    ($name:ident, $description:literal) => {
6        #[doc = $description]
7        #[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
8        #[serde(transparent)]
9        pub struct $name(String);
10
11        impl $name {
12            /// Creates an open code. Strict plan validation rejects empty or oversized codes.
13            #[must_use]
14            pub fn new(value: impl Into<String>) -> Self {
15                Self(value.into())
16            }
17
18            /// Returns the wire value.
19            #[must_use]
20            pub fn as_str(&self) -> &str {
21                &self.0
22            }
23
24            /// Consumes the code and returns its wire value.
25            #[must_use]
26            pub fn into_string(self) -> String {
27                self.0
28            }
29        }
30
31        impl From<&str> for $name {
32            fn from(value: &str) -> Self {
33                Self::new(value)
34            }
35        }
36
37        impl From<String> for $name {
38            fn from(value: String) -> Self {
39                Self::new(value)
40            }
41        }
42
43        impl AsRef<str> for $name {
44            fn as_ref(&self) -> &str {
45                self.as_str()
46            }
47        }
48
49        impl fmt::Display for $name {
50            fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
51                formatter.write_str(self.as_str())
52            }
53        }
54    };
55}
56
57open_code!(
58    StatusCode,
59    "An open result-status code shared by planner and later workflow result models."
60);
61open_code!(
62    WarningCode,
63    "An open warning code. Unknown future warnings remain representable."
64);
65open_code!(UncertaintyCode, "An open uncertainty kind or reason code.");
66open_code!(SubjectKind, "An open kind code for an evidence subject.");
67open_code!(
68    ScopeKind,
69    "An open kind code for a completeness-proof scope."
70);
71
72impl StatusCode {
73    pub const PLANNED: &'static str = "PLANNED";
74    pub const PREVIEW: &'static str = "PREVIEW";
75    pub const BLOCKED: &'static str = "BLOCKED";
76    pub const CONFLICT: &'static str = "CONFLICT";
77    pub const EVALUATED: &'static str = "EVALUATED";
78    pub const NO_CHANGE: &'static str = "NO_CHANGE";
79    pub const NOT_FOUND: &'static str = "NOT_FOUND";
80    pub const NOT_SUPPORTED: &'static str = "NOT_SUPPORTED";
81    pub const SOURCE_UNAVAILABLE: &'static str = "SOURCE_UNAVAILABLE";
82    pub const STALE_GRAPH: &'static str = "STALE_GRAPH";
83    pub const INVALID_PLAN: &'static str = "INVALID_PLAN";
84    pub const PREVIEW_OK: &'static str = "PREVIEW_OK";
85    pub const PREVIEW_BLOCKED: &'static str = "PREVIEW_BLOCKED";
86    pub const APPLIED: &'static str = "APPLIED";
87    pub const STALE: &'static str = "STALE";
88    pub const REPO_BUSY: &'static str = "REPO_BUSY";
89    pub const ROLLED_BACK: &'static str = "ROLLED_BACK";
90    pub const ROLLBACK_INCOMPLETE: &'static str = "ROLLBACK_INCOMPLETE";
91}