module std.reflect
std.reflect — comptime reflection (§15.2, D-1900..D-1913).
reflect(T) is known to the compiler and needs no import; this module only provides the names of the standard's
table (§1953) so that use std.reflect { reflect, TypeInfo } resolves. The values it returns exist only at
compile time: reflect(T).name, .kind, .fields, .variants, .methods, .attrs, … are folded to constants
and inline for over them is unrolled before type checking. The kinds and visibilities are the prelude enums
TypeKind and Visibility. Run-time reflection (rt, Any) is not implemented yet.
Example:
use std.reflect { reflect }
data Point {
x: i32
y: i32
}
fn main() io {
inline for f in reflect(Point).fields {
print("{f.name}: {f.type.name}")
}
}Output
x: i32 y: i32
Types
data AttrInfo | Comptime description of an attribute (@name(args)). |
data FieldInfo | Comptime description of a field of a data type, a tuple or an enum variant. |
data MethodInfo | Comptime description of a method. |
data ParamInfo | Comptime description of a method parameter. |
data TypeInfo | Comptime description of a type (reflect(T)). |
data VariantInfo | Comptime description of an enum variant. |
Functions
reflect | reflect(T); expanded by the compiler, never called at run time. |