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

Are defaults for an array of tables supported?

Open jordanmack opened this issue 6 years ago • 2 comments

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

jordanmack avatar Jan 28 '19 23:01 jordanmack

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.

matthiasbeyer avatar Mar 26 '21 16:03 matthiasbeyer

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.

jordanmack avatar Mar 27 '21 01:03 jordanmack