From cc791af9178128c140caa8e3b04807e1254a077c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Thu, 25 Aug 2022 10:21:40 +0200 Subject: [PATCH] roezio/config: Make Config.defaults and Config.default_section configurable at instanciation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- src/config.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/config.rs b/src/config.rs index feaf51ca..df6da054 100644 --- a/src/config.rs +++ b/src/config.rs @@ -64,23 +64,29 @@ impl fmt::Display for ConfigValue { } } -const DEFAULT_CONFIG: LazyCell>> = +pub(crate) const DEFAULT_CONFIG: LazyCell>> = LazyCell::new(|| HashMap::new()); pub(crate) struct Config<'a> { filename: PathBuf, - defaults: LazyCell>>, + 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>(filename: P) -> Self { + pub(crate) fn new>( + 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(), } }