feature. See also
. The project being documented here (as the example) is the Zig library itself.
meta.fieldInfo
pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeInfo(T))
File
Code
pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeInfo(T)) {
.@"struct" => struct { name: [:0]const u8, type: type, attrs: Type.Struct.FieldAttributes },
.@"union" => struct { name: [:0]const u8, type: type, attrs: Type.Union.FieldAttributes },
.@"enum" => struct { name: [:0]const u8, value: comptime_int },
.error_set => struct { name: [:0]const u8 },
else => @compileError("Expected struct, union, error set or enum type, found '" ++ @typeName(T) ++ "'"),
} {
const idx = @backingInt(field);
return switch (@typeInfo(T)) {
.@"struct" => |info| .{
.name = info.field_names[idx],
.type = info.field_types[idx],
.attrs = info.field_attrs[idx],
},
.@"union" => |info| .{
.name = info.field_names[idx],
.type = info.field_types[idx],
.attrs = info.field_attrs[idx],
},
.@"enum" => |info| .{
.name = info.field_names[idx],
.value = info.field_values[idx],
},
.error_set => |info| .{ .name = info.error_names.?[idx] },
else => @compileError("Expected struct, union, error set or enum type, found '" ++ @typeName(T) ++ "'"),
};
}