config-rs
config-rs copied to clipboard
Allow for weighting of config sources
Config::sources could be an ordered collection and the config sources themselves could have a weighting:
config::merge(config::Environment::with_prefix("rust")::with_weight(10));
The weight itself would be an arbitrary value, of course (and presumably the ordered collection would preserve insertion order within weighting).
config::merge(config::File::with_name("Settings").weight(10));
config::merge(config::Environment::with_prefix("rust").weight(5));
That feels fine. Interesting suggestion. I'll peg it to be added.
Thinking more on this .. I don't like .weight being on the source API
Config.merge_attakes a second,weight, parameter
config.merge_at(File::with_name("Settings"), 10);
- Complicate the return type story a bit more to make a fluid API here
config.merge(File::with_name("Settings")).with_weight(20);
Thoughts? Any other ideas?
I think that's fine. I'm trying to think of a situation where you'd really want to have multiple separate configs where the weight is actually associated with the sources you're merging from and drawing a blank. It's really down to the config using the source.
merge_at would be a new fn on impl Config, right?
Are you still interested in this, @nugend ?
I still think it's a worthwhile idea, but I don't have a practical application at the moment.