Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset to default values #48

Closed
vessd opened this issue Oct 17, 2017 · 1 comment
Closed

Reset to default values #48

vessd opened this issue Oct 17, 2017 · 1 comment
Labels

Comments

@vessd
Copy link

vessd commented Oct 17, 2017

I want to handle multiple configurations with the same fields.
I have the default settings and N configuration files. I want to merge the default settings with each file separately and as a result, get N structures with the settings.
How to reset values or parse them using only one source?

let mut config = Config::new();
config
    .set_default("host", "localhost")?
    .set_default("port", 21)?
    .set_default("user_id", 0)?;
config.merge(File::with_name("foo"))?;
let host_foo: Host = config.try_into()?;
config.reset(); // <-- reset to default
config.merge(File::with_name("bar"))?; // merge only with default values
let host_bar: Host = config.try_into()?;
@mehcode
Copy link
Owner

mehcode commented Jan 26, 2018

You can do config2.merge(config1). That would let you keep config1 from mutating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants