#[derive(Debug, Clone)]
pub enum ConfigSource {
EnvVar(String),
Default(String),
Nested,
File(String),
Programmatic,
}
impl ConfigSource {
pub fn is_env_var(&self) -> bool {
matches!(self, ConfigSource::EnvVar(_))
}
pub fn is_default(&self) -> bool {
matches!(self, ConfigSource::Default(_))
}
pub fn is_file(&self) -> bool {
matches!(self, ConfigSource::File(_))
}
pub fn description(&self) -> String {
match self {
ConfigSource::EnvVar(var) => format!("Environment variable: {}", var),
ConfigSource::Default(value) => format!("Default value: {}", value),
ConfigSource::Nested => "Nested configuration".to_string(),
ConfigSource::File(path) => format!("Configuration file: {}", path),
ConfigSource::Programmatic => "Programmatically set".to_string(),
}
}
}
impl std::fmt::Display for ConfigSource {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.description())
}
}