mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 11:07:46 +00:00
reflect: Add SliceOf, ArrayOf, StructOf, MapOf, FuncOf
This commit is contained in:
committed by
Ron Evans
parent
632357ffb9
commit
8a73502f11
@@ -499,3 +499,33 @@ type StructTag = reflectlite.StructTag
|
||||
func TypeFor[T any]() Type {
|
||||
return toType(reflectlite.TypeFor[T]())
|
||||
}
|
||||
|
||||
func SliceOf(t Type) Type {
|
||||
return toType(reflectlite.SliceOf(toRawType(t)))
|
||||
}
|
||||
|
||||
func ArrayOf(n int, t Type) Type {
|
||||
return toType(reflectlite.ArrayOf(n, toRawType(t)))
|
||||
}
|
||||
|
||||
func StructOf([]StructField) Type {
|
||||
return toType(reflectlite.StructOf([]reflectlite.StructField{}))
|
||||
}
|
||||
|
||||
func MapOf(key, value Type) Type {
|
||||
return toType(reflectlite.MapOf(toRawType(key), toRawType(value)))
|
||||
}
|
||||
|
||||
func FuncOf(in, out []Type, variadic bool) Type {
|
||||
rawIn := make([]reflectlite.Type, len(in))
|
||||
for i, t := range in {
|
||||
rawIn[i] = toRawType(t)
|
||||
}
|
||||
|
||||
rawOut := make([]reflectlite.Type, len(out))
|
||||
for i, t := range out {
|
||||
rawOut[i] = toRawType(t)
|
||||
}
|
||||
|
||||
return toType(reflectlite.FuncOf(rawIn, rawOut, variadic))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user