Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Function

fieldInfo

Public Function
std.meta.fieldInfo
pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeInfo(T))

Deprecated in favor of @typeInfo.

To be removed after 0.17.0 is tagged.

Params

File

meta.zig:253
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
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) ++ "'"),
    };
}