mehcode / config-rs

⚙️ Layered configuration system for Rust applications (with strong support for 12-factor applications).
Apache License 2.0
2.57k stars 213 forks source link

Are defaults for an array of tables supported? #94

Open jordanmack opened 5 years ago

jordanmack commented 5 years ago

Is it possible to set defaults for an array of tables, so that omitted values are automatically populated? I've checked through the examples and documentation and I can't find a clear answer.

Example:

[MyTableDefaults]
item1 = false
item2 = false
item3 = false
item4 = false
item5 = false

[[MyTable]]
item1 = true
item2 = true

[[MyTable]]
item3 = true
item4 = true

After merging the effective configuration would be:

[[MyTable]]
item1 = true
item2 = true
item3 = false
item4 = false
item5 = false

[[MyTable]]
item1 = false
item2 = false
item3 = true
item4 = true
item5 = false
matthiasbeyer commented 3 years ago

Not sure whether this is still relevant, but I guess that's rather hard to achieve with the current implementation of the crate and maybe not even possible at all.

jordanmack commented 3 years ago

I believe it is still beneficial, but I don't know about absolute necessity. I don't remember much about the implementation anymore or how feasible it would be.

What I do remember is my workaround. I just use another function to copy the values from MyTableDefaults to each MyTable instance when they don't exist. It's not a very clean way of doing it, but it accomplishes my needs.