generics
Explore the following sections to learn more:
generics
import "github.com/gemini-oss/rego/pkg/common/generics"
pkg/common/generics/generics.go
Index
- func DerefGeneric[E any]() (reflect.Type, bool)
- func MarshalGeneric[T any, M any](t *T) ([]byte, error)
- func Pointer[T any](val T) *T
- func UnmarshalGeneric[T any, M any](data []byte) (*T, error)
func DerefGeneric
func DerefGeneric[E any]() (reflect.Type, bool)
DerefGeneric returns the concrete struct type of E and whether E itself is a pointer.
func MarshalGeneric
func MarshalGeneric[T any, M any](t *T) ([]byte, error)
MarshalGeneric is the exact dual of UnmarshalGeneric.
– T is the concrete wrapper type (e.g. License[M])
– M is the generic field type (e.g. LicensePOST)
The function encodes *t to JSON, flattening the one field whose type is M (or *M) and every other field that carries the `,inline` tag exactly the way encoding/json does for embedded structs.
func Pointer
func Pointer[T any](val T) *T
Pointer returns a pointer to the value of type T.
func UnmarshalGeneric
func UnmarshalGeneric[T any, M any](data []byte) (*T, error)
UnmarshalGeneric unmarshals JSON into a generic struct T that contains an inline generic field of type M. The generic field is automatically detected by scanning T for a field whose type is M (or a pointer to M). All keys that are not consumed by other fields are assumed to belong to this generic field.
Generated by gomarkdoc