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

UnionTagWithoutUninitializable

Private Type Function
std.testing.Smith.UnionTagWithoutUninitializable
fn UnionTagWithoutUninitializable(T: type) type

File

testing/Smith.zig:359
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
fn UnionTagWithoutUninitializable(T: type) type {
    const u = @typeInfo(T).@"union";
    const Tag = u.tag_type orelse @compileError("union must have tag");
    const e = @typeInfo(Tag).@"enum";
    var field_names: [e.field_names.len][]const u8 = undefined;
    var field_values: [e.field_names.len]e.tag_type = undefined;
    var n_fields = 0;
    for (u.field_names, u.field_types) |f_name, f_type| {
        switch (f_type) {
            noreturn => continue,
            else => {},
        }
        field_names[n_fields] = f_name;
        field_values[n_fields] = @backingInt(@field(Tag, f_name));
        n_fields += 1;
    }
    return @Enum(e.tag_type, .exhaustive, field_names[0..n_fields], field_values[0..n_fields]);
}