IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

struct_field_index_by_name

struct_field_index_by_name[T: AnyType, name: StringLiteral[name.value]]() -> Int

Deprecated: use reflect[T]().field_index[name]() instead.

Returns the index of the field with the given name in struct T.

This function provides compile-time lookup of a struct field's index by name. It produces a compile error if the field name does not exist in the struct.

Note: T must be a concrete type, not a generic type parameter. See the module documentation for details on this limitation.

Deprecated: Use reflect[T]().field_index[name]() instead.

Parameters:

Returns:

Int: The zero-based index of the field in the struct.