pub fn fieldIndex(comptime T: type, comptime name: []const u8) ?comptime_int T: typename: []const u8729
730
731
732
733
734
735pub fn fieldIndex(comptime T: type, comptime name: []const u8) ?comptime_int {
inline for (fieldNames(T), 0..) |field_name, i| {
if (mem.eql(u8, field_name, name))
return i;
}
return null;
}
Given a type and a name, return the field index according to source order. Returns
nullif the field is not found.