Mojo function
struct_field_index_by_name
struct_field_index_by_name[T: AnyType, name: StringLiteral[value]]() -> Int
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.
Parameters:
- T (
AnyType): A concrete struct type. - name (
StringLiteral): The name of the field to look up.
Returns:
Int: The zero-based index of the field in the struct.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!