We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
encode/1
1 parent 469e268 commit 031fce4Copy full SHA for 031fce4
1 file changed
vlib/toml/toml.v
@@ -167,13 +167,18 @@ fn decode_struct[T](doc Any, mut typ T) {
167
// encode encodes the type `T` into a TOML string.
168
// If `T` has a custom `.to_toml()` method, it will be used instead of the default.
169
pub fn encode[T](typ T) string {
170
- $for method in T.methods {
171
- $if method.name == 'to_toml' {
172
- return typ.$method()
+ $if T is $struct {
+ $for method in T.methods {
+ $if method.name == 'to_toml' {
173
+ return typ.$method()
174
+ }
175
}
176
+ mp := encode_struct[T](typ)
177
+ return mp.to_toml()
178
+ } $else {
179
+ $compile_error('Currently only type `struct` is supported for `T` to encode as TOML')
180
- mp := encode_struct[T](typ)
- return mp.to_toml()
181
+ return ''
182
183
184
fn encode_struct[T](typ T) map[string]Any {
0 commit comments