roezio/config: Make Config.defaults and Config.default_section configurable at instanciation

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2022-08-25 10:21:40 +02:00
parent 0b5ed75e90
commit cc791af917
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -64,23 +64,29 @@ impl fmt::Display for ConfigValue {
}
}
const DEFAULT_CONFIG: LazyCell<HashMap<&str, HashMap<&str, ConfigValue>>> =
pub(crate) const DEFAULT_CONFIG: LazyCell<HashMap<&str, HashMap<&str, ConfigValue>>> =
LazyCell::new(|| HashMap::new());
pub(crate) struct Config<'a> {
filename: PathBuf,
defaults: LazyCell<HashMap<&'a str, HashMap<&'a str, ConfigValue>>>,
defaults: HashMap<&'a str, HashMap<&'a str, ConfigValue>>,
default_section: &'a str,
ini: Ini,
}
impl Config<'static> {
impl<'a> Config<'a> {
/// Create a new Config object
pub(crate) fn new<P: Into<PathBuf>>(filename: P) -> Self {
pub(crate) fn new<P: Into<PathBuf>>(
filename: P,
defaults: HashMap<&'a str, HashMap<&'a str, ConfigValue>>,
default_section: Option<&'a str>,
) -> Self {
// TODO: read ini file.
Config {
filename: filename.into(),
defaults: DEFAULT_CONFIG,
defaults,
default_section: default_section.unwrap_or("default"),
ini: Ini::new(),
}
}