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

Extended

Public Type Function
std.Build.Configuration.Storage.Extended
pub fn Extended(comptime BaseFlags: type, comptime U: type) type

The field indexes into an auxilary buffer, with the first element being a packed struct that contains the tag.

Values

Functions

pub fn tag(this: @This(), c: *const Configuration) @FieldType(BaseFlags, "tag")
pub fn cast(this: @This(), c: *const Configuration, comptime S: type) ?S
pub fn get(this: @This(), buffer: []const u32) U

File

Build/Configuration.zig:2597
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
    pub fn Extended(comptime BaseFlags: type, comptime U: type) type {
        return enum(u32) {
            _,

            pub const storage: Storage = .extended;

            pub fn tag(this: @This(), c: *const Configuration) @FieldType(BaseFlags, "tag") {
                const base_flags: BaseFlags = @bitCast(c.extra[@backingInt(this)]);
                return base_flags.tag;
            }

            pub fn cast(this: @This(), c: *const Configuration, comptime S: type) ?S {
                const wanted_tag = blk: {
                    const info = @typeInfo(S.Flags).@"struct";
                    break :blk info.field_attrs[0].defaultValue(info.field_types[0]).?;
                };
                const base_flags: BaseFlags = @bitCast(c.extra[@backingInt(this)]);
                if (base_flags.tag != wanted_tag) return null;
                var i: usize = @backingInt(this);
                return data(c.extra, &i, S);
            }

            pub fn get(this: @This(), buffer: []const u32) U {
                var i: usize = @backingInt(this);
                const base_flags: BaseFlags = @bitCast(buffer[i]);
                return switch (base_flags.tag) {
                    inline else => |t| @unionInit(U, @tagName(t), data(buffer, &i, @FieldType(U, @tagName(t)))),
                };
            }
        };
    }