Zig 0.17.0-dev (Split by item)

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 library itself.

fieldInfo

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

File

lib/std/meta.zig:249

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) ++ "'"),
    };
}