configbuilder-pattern-substitution 0.1.0

configbuilder-pattern: substitution domain, trait contract + reference implementation. No -svc counterpart.
Documentation
use std::fmt;

/// Error type for environment variable substitution failures.
#[derive(Debug, Clone, PartialEq)]
pub enum SubstitutionError {
    /// A referenced environment variable does not exist in the process environment.
    VariableNotFound {
        /// Name of the missing variable.
        var_name: String,
        /// Config file or section where the placeholder appeared.
        location: String,
    },
    /// A variable was found but rejected by the active substitution policy.
    VariableRejected {
        /// Name of the rejected variable.
        var_name: String,
        /// Human-readable reason the policy rejected the variable.
        reason: String,
        /// Description of the policy that rejected the variable.
        policy: String,
    },
    /// The substitution syntax in the config value is malformed.
    InvalidSubstitutionSyntax {
        /// The raw config value containing the malformed placeholder.
        value: String,
        /// Description of the syntax error.
        reason: String,
    },
}

impl fmt::Display for SubstitutionError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            SubstitutionError::VariableNotFound { var_name, location } => write!(
                f,
                "Environment variable '{}' referenced in config (at {}) but not found",
                var_name, location
            ),
            SubstitutionError::VariableRejected {
                var_name,
                reason,
                policy,
            } => write!(
                f,
                "Environment variable '{}' not allowed by validation policy ({}): {}",
                var_name, policy, reason
            ),
            SubstitutionError::InvalidSubstitutionSyntax { value, reason } => {
                write!(f, "Invalid substitution syntax in '{}': {}", value, reason)
            }
        }
    }
}

impl std::error::Error for SubstitutionError {}