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:
parent
0b5ed75e90
commit
cc791af917
1 changed files with 11 additions and 5 deletions
|
@ -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(),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue