Skip to main content

Mojo struct

ReflectedType

struct ReflectedType[T: AnyType]

Wrapper struct for compile-time type values from reflection.

This struct wraps a !kgen.non_struct_type value as a type parameter, allowing type values to be returned from functions and passed around at compile time.

Example:

# Get the type of field "x" in MyStruct
comptime field_type = struct_field_type_by_name[MyStruct, "x"]()
# Access the underlying type via the T parameter
var value: field_type.T = 42

Parameters

  • T (AnyType): The wrapped type value.

Implemented traits

AnyType, Copyable, ImplicitlyCopyable, ImplicitlyDestructible, Movable, RegisterPassable, TrivialRegisterPassable

Methods

__init__

__init__() -> Self

Create a ReflectedType instance.

Was this page helpful?