Skip to main content

Mojo function

reflect

reflect[T: AnyType]() -> Reflected[T]

Returns a compile-time reflection handle for type T.

Example:

from std.reflection import reflect

struct Point:
    var x: Int
    var y: Float64

def main():
    comptime r = reflect[Point]()
    print(r.field_count())  # 2

Parameters:

  • T (AnyType): The type to introspect.

Returns:

Reflected[T]: A Reflected[T] handle exposing introspection methods.

Was this page helpful?