#![forbid(unsafe_code)]
#![deny(missing_docs)]
use std::fmt;
use sim_kernel::{Expr, Symbol, id::SymbolError};
pub mod merge;
pub mod path;
pub mod report;
pub mod shape;
pub mod source;
pub mod table;
pub mod view;
pub use merge::{ConfigLayer, EffectiveConfig, MergeTrace, merge_layers};
pub use path::{ConfigRoots, lib_config_path};
pub use report::{ConfigReport, ConfigReportEntry};
pub use shape::{ConfigSecretField, ConfigShape, ConfigShapeResult, LibConfigDefaults};
pub use source::{ConfigSource, ProbeMode};
pub use table::{ConfigDir, ConfigTable, lib_symbol_from_str};
pub use view::ConfigView;
pub type ConfigResult<T> = Result<T, ConfigError>;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ConfigError {
NonDirExpr,
NonTableExpr,
NonTableConfig {
lib: Symbol,
},
UnsupportedDirKey {
key: Expr,
},
InvalidLibId {
id: String,
},
InvalidPathSegment {
segment: String,
},
MissingField {
key: String,
},
TypeMismatch {
key: String,
expected: &'static str,
},
}
impl From<SymbolError> for ConfigError {
fn from(error: SymbolError) -> Self {
Self::InvalidLibId {
id: error.to_string(),
}
}
}
impl fmt::Display for ConfigError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NonDirExpr => f.write_str("config dir must be an Expr::Map"),
Self::NonTableExpr => f.write_str("config table must be an Expr::Map"),
Self::NonTableConfig { lib } => {
write!(f, "config for `{}` must be a table", lib.as_qualified_str())
}
Self::UnsupportedDirKey { key } => {
write!(f, "config dir key {key:?} is not a supported library id")
}
Self::InvalidLibId { id } => write!(f, "invalid config library id `{id}`"),
Self::InvalidPathSegment { segment } => {
write!(f, "invalid config path segment `{segment}`")
}
Self::MissingField { key } => write!(f, "config field `{key}` is missing"),
Self::TypeMismatch { key, expected } => {
write!(f, "config field `{key}` is not {expected}")
}
}
}
}
impl std::error::Error for ConfigError {}