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

How to merge sources with existing default values? #628

Open
cbeuw opened this issue Dec 27, 2024 · 0 comments
Open

How to merge sources with existing default values? #628

cbeuw opened this issue Dec 27, 2024 · 0 comments

Comments

@cbeuw
Copy link

cbeuw commented Dec 27, 2024

Suppose I have this config struct

#[derive(Debug, Deserialize)]
struct MyConfig {
    // ...
}

impl Default for MyConfig {
    fn default() -> MyConfig {
        // some complex logic
    }
}

I want to produce a MyConfig, where values explicitly set in config.toml are used, otherwise, the default implementation is used.

Something like

Config::builder().
    .add_source(File::with_name("config.toml"))
    .set_default(???, MyConfig::default())
    .build()?;

But I couldn't figure out a way to do this. This seems like a very common use case, so I feel like I'm missing something.

@cbeuw cbeuw changed the title How merge sources with existing default values? How to merge sources with existing default values? Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant