mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: replace generic <>
with []
- part 2 (#16536)
This commit is contained in:
@@ -329,7 +329,7 @@ fn (a Any) value_(value Any, key []string) Any {
|
||||
|
||||
// reflect returns `T` with `T.<field>`'s value set to the
|
||||
// value of any 1st level TOML key by the same name.
|
||||
pub fn (a Any) reflect<T>() T {
|
||||
pub fn (a Any) reflect[T]() T {
|
||||
mut reflected := T{}
|
||||
$for field in T.fields {
|
||||
mut toml_field_name := field.name
|
||||
|
@@ -36,7 +36,7 @@ fn (mut e Employee) from_toml(any toml.Any) {
|
||||
|
||||
fn test_encode_and_decode() {
|
||||
x := Employee{'Peter', 28, 95000.5, true, .worker}
|
||||
s := toml.encode<Employee>(x)
|
||||
s := toml.encode[Employee](x)
|
||||
eprintln('Employee x: ${s}')
|
||||
assert s == r'name = "Peter"
|
||||
age = 28
|
||||
@@ -44,7 +44,7 @@ salary = 95000.5
|
||||
is_human = true
|
||||
title = 2'
|
||||
|
||||
y := toml.decode<Employee>(s) or {
|
||||
y := toml.decode[Employee](s) or {
|
||||
println(err)
|
||||
assert false
|
||||
return
|
||||
|
@@ -62,9 +62,9 @@ mut:
|
||||
fn test_reflect() {
|
||||
toml_doc := toml.parse_text(toml_text) or { panic(err) }
|
||||
|
||||
mut user := toml_doc.reflect<User>()
|
||||
user.bio = toml_doc.value('bio').reflect<Bio>()
|
||||
user.remap = toml_doc.value('field_remap').reflect<FieldRemap>()
|
||||
mut user := toml_doc.reflect[User]()
|
||||
user.bio = toml_doc.value('bio').reflect[Bio]()
|
||||
user.remap = toml_doc.value('field_remap').reflect[FieldRemap]()
|
||||
|
||||
assert user.name == 'Tom'
|
||||
assert user.age == 45
|
||||
|
@@ -13,7 +13,7 @@ pub struct Null {
|
||||
}
|
||||
|
||||
// decode decodes a TOML `string` into the target type `T`.
|
||||
pub fn decode<T>(toml_txt string) !T {
|
||||
pub fn decode[T](toml_txt string) !T {
|
||||
doc := parse_text(toml_txt)!
|
||||
mut typ := T{}
|
||||
typ.from_toml(doc.to_any())
|
||||
@@ -22,7 +22,7 @@ pub fn decode<T>(toml_txt string) !T {
|
||||
|
||||
// encode encodes the type `T` into a TOML string.
|
||||
// Currently encode expects the method `.to_toml()` exists on `T`.
|
||||
pub fn encode<T>(typ T) string {
|
||||
pub fn encode[T](typ T) string {
|
||||
return typ.to_toml()
|
||||
}
|
||||
|
||||
@@ -194,8 +194,8 @@ pub fn (d Doc) to_any() Any {
|
||||
|
||||
// reflect returns `T` with `T.<field>`'s value set to the
|
||||
// value of any 1st level TOML key by the same name.
|
||||
pub fn (d Doc) reflect<T>() T {
|
||||
return d.to_any().reflect<T>()
|
||||
pub fn (d Doc) reflect[T]() T {
|
||||
return d.to_any().reflect[T]()
|
||||
}
|
||||
|
||||
// value queries a value from the TOML document.
|
||||
|
Reference in New Issue
Block a user