config-rs icon indicating copy to clipboard operation
config-rs copied to clipboard

Allow for weighting of config sources

Open nugend opened this issue 8 years ago • 5 comments
trafficstars

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).

nugend avatar Jan 25 '17 18:01 nugend

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.

mehcode avatar Jan 25 '17 19:01 mehcode

Thinking more on this .. I don't like .weight being on the source API

  1. Config.merge_at takes a second, weight, parameter
config.merge_at(File::with_name("Settings"), 10);
  1. 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?

mehcode avatar Jun 23 '17 07:06 mehcode

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?

nugend avatar Jun 23 '17 12:06 nugend

Are you still interested in this, @nugend ?

matthiasbeyer avatar Mar 18 '21 14:03 matthiasbeyer

I still think it's a worthwhile idea, but I don't have a practical application at the moment.

nugend avatar Mar 18 '21 15:03 nugend