config-rs
config-rs copied to clipboard
[Question] to merge borrowing
Hi,
ist there a way to do optional merging without cloning?
If the merge fails, it should stay at the settings before the try to merge.
Because File::from... seems to be something which can not panic, the panic needs to occur in merge, is this correct?
At least there is nothing I can check the Result or Option from File::from....
So the only way I've found to get this to work is cloning before the merge, and sadly, I've to clone also the Result, because merge borrows in the result...
let mut settings = Config::default();
settings.set_default(...).unwrap();
[...]
let default_settings = settings.clone();
let cfgfile = "default.cfg";
let src = File::from_str(cfgfile, FileFormat::Ini);
let merge_res = settings.merge(src);
match merge_res {
Err(err) => {
default_settings
}
Ok(s) => s.clone(),
}
This is #57
Sadly there isn't an easy way to fix this with the current architecture. I'm aiming at changing that in 0.10 which I'm currently spiking out as a complete rewrite (which I'll then backport changes to master).
Now File can be used like File::new("default.cfg", FileFormat::Ini).required(false) which will let it not error if the file is missing.