How to merge sources with existing default values?
Open
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 3.2k
- Forks
- 265
- Avg merge
- 2h 42m
- Merged PRs (30d)
- 4
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the Config::builder, File::with_name, set_default, and build APIs referenced in the issue. Determine whether the existing source and default-value mechanisms can express a MyConfig-wide fallback, and define the expected behavior for explicitly configured versus defaulted fields.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100