mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
toml: add encode<T> and decode<T> (#13244)
This commit is contained in:
@@ -12,6 +12,20 @@ import toml.parser
|
||||
pub struct Null {
|
||||
}
|
||||
|
||||
// decode decodes a TOML `string` into the target type `T`.
|
||||
pub fn decode<T>(toml_txt string) ?T {
|
||||
doc := parse_text(toml_txt) ?
|
||||
mut typ := T{}
|
||||
typ.from_toml(doc.to_any())
|
||||
return typ
|
||||
}
|
||||
|
||||
// encode encodes the type `T` into a JSON string.
|
||||
// Currently encode expects the method `.to_toml()` exists on `T`.
|
||||
pub fn encode<T>(typ T) string {
|
||||
return typ.to_toml()
|
||||
}
|
||||
|
||||
// DateTime is the representation of an RFC 3339 datetime string.
|
||||
pub struct DateTime {
|
||||
datetime string
|
||||
|
||||
Reference in New Issue
Block a user