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 Type Function

EnumFieldStruct

Public Type Function
std.enums.EnumFieldStruct
pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_default: ?Data) type

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.

File

enums.zig:33
33
34
35
36
37
38
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;
    const field_names = @typeInfo(E).@"enum".field_names;
    return @Struct(.auto, null, field_names, &@splat(Data), &@splat(.{ .default_value_ptr = default_ptr }));
}