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.

EnumFieldStruct

Returns a struct with a field matching each unique named enum element. If the enum is extern and has multiple names for the same value, only the first name is used. Each field is of type Data and has the provided default, which may be undefined.

enums.EnumFieldStruct
pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_default: ?Data) type

File

lib/std/enums.zig:33

Code

pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_default: ?Data) type {
    @setEvalBranchQuota(@typeInfo(E).@"enum".field_names.len + eval_branch_quota_cushion);
    const default_ptr: ?*const anyopaque = if (field_default) |d| @ptrCast(&d) else null;
    return @Struct(.auto, null, std.meta.fieldNames(E), &@splat(Data), &@splat(.{ .default_value_ptr = default_ptr }));
}