mirror of
https://github.com/vlang/v.git
synced 2025-08-04 02:07:28 -04:00
This commit is contained in:
parent
469e268c79
commit
031fce4361
@ -167,13 +167,18 @@ fn decode_struct[T](doc Any, mut typ T) {
|
|||||||
// encode encodes the type `T` into a TOML string.
|
// encode encodes the type `T` into a TOML string.
|
||||||
// If `T` has a custom `.to_toml()` method, it will be used instead of the default.
|
// If `T` has a custom `.to_toml()` method, it will be used instead of the default.
|
||||||
pub fn encode[T](typ T) string {
|
pub fn encode[T](typ T) string {
|
||||||
$for method in T.methods {
|
$if T is $struct {
|
||||||
$if method.name == 'to_toml' {
|
$for method in T.methods {
|
||||||
return typ.$method()
|
$if method.name == 'to_toml' {
|
||||||
|
return typ.$method()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
mp := encode_struct[T](typ)
|
||||||
|
return mp.to_toml()
|
||||||
|
} $else {
|
||||||
|
$compile_error('Currently only type `struct` is supported for `T` to encode as TOML')
|
||||||
}
|
}
|
||||||
mp := encode_struct[T](typ)
|
return ''
|
||||||
return mp.to_toml()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode_struct[T](typ T) map[string]Any {
|
fn encode_struct[T](typ T) map[string]Any {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user