feat: allow "zeroed" values as defaults
parent
6678040d30
commit
8bd7ce0b60
7
conf.v
7
conf.v
|
@ -102,8 +102,11 @@ pub fn load<T>(ld LoadConfig) !T {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, if there's no env var present either, we check whether the
|
// Finally, if there's no env var present either, we check whether the
|
||||||
// variable has a default value
|
// variable has a default value. Variables defined with an "empty
|
||||||
if !has_value.exists(field.name) {
|
// default" will always be marked as containing a value.
|
||||||
|
if 'empty_default' in field.attrs {
|
||||||
|
has_value.add(field.name)
|
||||||
|
} else if !has_value.exists(field.name) {
|
||||||
mut has_default := false
|
mut has_default := false
|
||||||
|
|
||||||
$if field.typ is string {
|
$if field.typ is string {
|
||||||
|
|
|
@ -170,3 +170,14 @@ fn test_string_absent_default_env() {
|
||||||
some_string: 'env'
|
some_string: 'env'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct SingleConfDefaultEmpty {
|
||||||
|
some_string string [empty_default]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_string_absent_default_empty() {
|
||||||
|
conf := load<SingleConfDefaultEmpty>(default_path: 'test/empty.toml')!
|
||||||
|
assert conf == SingleConfDefaultEmpty{
|
||||||
|
some_string: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue