weavatrix-refactor-plan 0.1.1

Evidence metadata, validation profiles, and canonical fingerprints for Weavatrix refactor plans
Documentation
use serde::{Deserialize, Serialize};
use std::fmt;

macro_rules! open_code {
    ($name:ident, $description:literal) => {
        #[doc = $description]
        #[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
        #[serde(transparent)]
        pub struct $name(String);

        impl $name {
            /// Creates an open code. Strict plan validation rejects empty or oversized codes.
            #[must_use]
            pub fn new(value: impl Into<String>) -> Self {
                Self(value.into())
            }

            /// Returns the wire value.
            #[must_use]
            pub fn as_str(&self) -> &str {
                &self.0
            }

            /// Consumes the code and returns its wire value.
            #[must_use]
            pub fn into_string(self) -> String {
                self.0
            }
        }

        impl From<&str> for $name {
            fn from(value: &str) -> Self {
                Self::new(value)
            }
        }

        impl From<String> for $name {
            fn from(value: String) -> Self {
                Self::new(value)
            }
        }

        impl AsRef<str> for $name {
            fn as_ref(&self) -> &str {
                self.as_str()
            }
        }

        impl fmt::Display for $name {
            fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
                formatter.write_str(self.as_str())
            }
        }
    };
}

open_code!(
    StatusCode,
    "An open result-status code shared by planner and later workflow result models."
);
open_code!(
    WarningCode,
    "An open warning code. Unknown future warnings remain representable."
);
open_code!(UncertaintyCode, "An open uncertainty kind or reason code.");
open_code!(SubjectKind, "An open kind code for an evidence subject.");
open_code!(
    ScopeKind,
    "An open kind code for a completeness-proof scope."
);

impl StatusCode {
    pub const PLANNED: &'static str = "PLANNED";
    pub const PREVIEW: &'static str = "PREVIEW";
    pub const BLOCKED: &'static str = "BLOCKED";
    pub const CONFLICT: &'static str = "CONFLICT";
    pub const EVALUATED: &'static str = "EVALUATED";
    pub const NO_CHANGE: &'static str = "NO_CHANGE";
    pub const NOT_FOUND: &'static str = "NOT_FOUND";
    pub const NOT_SUPPORTED: &'static str = "NOT_SUPPORTED";
    pub const SOURCE_UNAVAILABLE: &'static str = "SOURCE_UNAVAILABLE";
    pub const STALE_GRAPH: &'static str = "STALE_GRAPH";
    pub const INVALID_PLAN: &'static str = "INVALID_PLAN";
    pub const PREVIEW_OK: &'static str = "PREVIEW_OK";
    pub const PREVIEW_BLOCKED: &'static str = "PREVIEW_BLOCKED";
    pub const APPLIED: &'static str = "APPLIED";
    pub const STALE: &'static str = "STALE";
    pub const REPO_BUSY: &'static str = "REPO_BUSY";
    pub const ROLLED_BACK: &'static str = "ROLLED_BACK";
    pub const ROLLBACK_INCOMPLETE: &'static str = "ROLLBACK_INCOMPLETE";
}