You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importtomlstructObject {
text string
integer int
}
fnmain() {
null_toml:= toml.parse_text('')!object:= null_toml.decode[Object]()!println(object.text)
println(object.integer)
}
returns
toml.Any(toml.Null{})
0
and I believe that there is no way to change this behavior (You can use .reflect() instead of .decode() to get an empty string instead of toml.Any(toml.Null{}), though).
I think it is very useful if Vlang has a way to provide default values:
option 1) by an attribute, like
structObject {
text string [toml_default: 'hello']
integer int [toml_default: 123]
}
or
option 2) by respecting the default value of the field, like
structObject {
text string='hello'
integer int=123
}
Use Case
This should be useful, for example, when building an application that uses TOML format for its configuration file.
Proposed Solution
No response
Other Information
json.decode() respects the default value of the field:
syobocat
changed the title
Provide a way to set default values when decoding TOML
toml: Provide a way to set default values when decoding TOML
Sep 8, 2024
Describe the feature
Currently, this code:
returns
and I believe that there is no way to change this behavior (You can use
.reflect()
instead of.decode()
to get an empty string instead oftoml.Any(toml.Null{})
, though).I think it is very useful if Vlang has a way to provide default values:
option 1) by an attribute, like
or
option 2) by respecting the default value of the field, like
Use Case
This should be useful, for example, when building an application that uses TOML format for its configuration file.
Proposed Solution
No response
Other Information
json.decode()
respects the default value of the field:Acknowledgements
Version used
V 0.4.7 620e064
Environment details (OS name and version, etc.)
V full version: V 0.4.7 e9c9580.620e064
OS: macos, macOS, 14.6.1, 23G93
Processor: 8 cpus, 64bit, little endian, Apple M3
getwd: /Users/syobon
vexe: /Users/syobon/.v/v
vexe mtime: 2024-09-07 12:37:14
vroot: OK, value: /Users/syobon/.v
VMODULES: OK, value: /Users/syobon/.vmodules
VTMP: OK, value: /tmp/v_501
Git version: git version 2.46.0
Git vroot status: weekly.2024.36-18-g620e0641 (2 commit(s) behind V master)
.git/config present: true
CC version: Apple clang version 15.0.0 (clang-1500.3.9.4)
thirdparty/tcc status: thirdparty-macos-arm64 713692d4
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
The text was updated successfully, but these errors were encountered: