Standard library
Reflection
Runtime kind tags for values and collection keys.
Introduction
Runtime kind tags for values and collection keys. Import std/reflect to bind the module as reflect. Call free functions as reflect.name(...). Struct methods use a receiver value.
/ std/reflect
This page is the package reference for std/reflect. Private helpers used only by co-located tests are not listed.
Constants
Constants are module values you read without calling. Each constant below has its own heading.
KIND_INT
Kind tag constant for integer values. Call form: reflect.KIND_INT.
/ std/reflect
$ k = reflect.KIND_INT
Parameters: No parameters. Constant export. Returns: Integer kind tag for ints.
KIND_LIST
Kind tag constant for list values. Call form: reflect.KIND_LIST.
/ std/reflect
$ k = reflect.KIND_LIST
Parameters: No parameters. Constant export. Returns: Integer kind tag for lists.
KIND_STRING
Kind tag constant for string values. Call form: reflect.KIND_STRING.
/ std/reflect
$ k = reflect.KIND_STRING
Parameters: No parameters. Constant export. Returns: Integer kind tag for strings.
KIND_STRUCT
Kind tag constant for struct values. Call form: reflect.KIND_STRUCT.
/ std/reflect
$ k = reflect.KIND_STRUCT
Parameters: No parameters. Constant export. Returns: Integer kind tag for structs.
KIND_FLOAT
Kind tag constant for float values. Call form: reflect.KIND_FLOAT.
/ std/reflect
$ k = reflect.KIND_FLOAT
Parameters: No parameters. Constant export. Returns: Integer kind tag for floats.
KIND_BYTES
Kind tag constant for bytes values. Call form: reflect.KIND_BYTES.
/ std/reflect
$ k = reflect.KIND_BYTES
Parameters: No parameters. Constant export. Returns: Integer kind tag for bytes.
Functions
Free functions on reflect. Each function has a short description, an example, then parameters and return shape.
kind
Returns the runtime kind tag for a value. Call form: reflect.kind(v).
/ std/reflect
$ k = reflect.kind(42)
Parameters: v: any value. Returns: Integer kind tag (compare with KIND_* constants).
kind_name
Returns a human-readable name for the runtime kind of v. Call form: reflect.kind_name(v).
/ std/reflect
$ s = reflect.kind_name(42)
Parameters: v: any value. Returns: Kind name string.
key_bytes
Returns a stable key encoding for value v. Call form: reflect.key_bytes(v).
/ std/reflect
$ b = reflect.key_bytes("a")Parameters: v: any value. Returns: Key bytes.
is_int
Reports whether v is an integer. Call form: reflect.is_int(v).
/ std/reflect
$ ok = reflect.is_int(42)
Parameters: v: any value. Returns: Boolean.
is_string
Reports whether v is a string. Call form: reflect.is_string(v).
/ std/reflect
$ ok = reflect.is_string("a")Parameters: v: any value. Returns: Boolean.
is_bytes
Reports whether v is bytes. Call form: reflect.is_bytes(v).
/ std/reflect
$ ok = reflect.is_bytes(b'a')
Parameters: v: any value. Returns: Boolean.
is_list
Reports whether v is a list. Call form: reflect.is_list(v).
/ std/reflect
$ ok = reflect.is_list([1])
Parameters: v: any value. Returns: Boolean.
is_float
Reports whether v is a float. Call form: reflect.is_float(v).
/ std/reflect
$ ok = reflect.is_float(<f64>1.0)
Parameters: v: any value. Returns: Boolean.
is_struct
Reports whether v is a struct. Call form: reflect.is_struct(v).
/ std/reflect
$ ok = reflect.is_struct({ x: 1 })Parameters: v: any value. Returns: Boolean.