OxL Reference

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:

oxl✓ checked in CI
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 AttrInfoComptime description of an attribute (@name(args)).
data FieldInfoComptime description of a field of a data type, a tuple or an enum variant.
data MethodInfoComptime description of a method.
data ParamInfoComptime description of a method parameter.
data TypeInfoComptime description of a type (reflect(T)).
data VariantInfoComptime description of an enum variant.

Functions

reflectreflect(T); expanded by the compiler, never called at run time.

See also