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

UnionList

Public Type Function
std.Build.Configuration.Storage.UnionList
pub fn UnionList(
        comptime flags_arg: @EnumLiteral(),
        comptime flag_arg: @EnumLiteral(),
        comptime UnionArg: type,
    ) type

UnionArg is a tagged union with a small integer for the enum tag.

A field in flags determines whether the metadata is present.

The metadata is bit-packed consecutive packed struct which is the UnionArg enum tag combined with a "last" marker boolean field. When "last" is true, the element is the last one, providing the length of the list.

Following is each element of the list; each bitcastable to u32.

Fields

data: ?*const anyopaque

When serializing it is UnionArg slice pointer. When deserializing it is extra index of first UnionArg element.

len: usize

Structs

Values

Functions

pub fn init(s: []const Union) @This()

Valid to call only when serializing.

pub fn slice(this: *const @This(), extra: []const u32) []const u32

Valid to call only when deserializing.

pub fn get(this: *const @This(), extra: []const u32, i: usize) Union

Valid to call only when deserializing.

pub fn tag(this: *const @This(), extra: []const u32, i: usize) Tag

Valid to call only when deserializing.

fn extraLen(len: usize) usize

File

Build/Configuration.zig:2711
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
    pub fn UnionList(
        comptime flags_arg: @EnumLiteral(),
        comptime flag_arg: @EnumLiteral(),
        comptime UnionArg: type,
    ) type {
        return struct {
            /// When serializing it is UnionArg slice pointer.
            /// When deserializing it is extra index of first UnionArg element.
            data: ?*const anyopaque,
            len: usize,

            pub const storage: Storage = .union_list;
            pub const flags = flags_arg;
            pub const flag = flag_arg;
            pub const Union = UnionArg;

            pub const Tag = @typeInfo(Union).@"union".tag_type.?;
            pub const MetaInt = @Int(.unsigned, @bitSizeOf(Tag) + 1);
            pub const Meta = packed struct(MetaInt) {
                tag: Tag,
                last: bool,
            };

            /// Valid to call only when serializing.
            pub fn init(s: []const Union) @This() {
                return .{ .data = s.ptr, .len = s.len };
            }

            /// Valid to call only when deserializing.
            pub fn slice(this: *const @This(), extra: []const u32) []const u32 {
                return extra[@intFromPtr(this.data)..][0..this.len];
            }

            /// Valid to call only when deserializing.
            pub fn get(this: *const @This(), extra: []const u32, i: usize) Union {
                const elem = slice(this, extra)[i];
                return switch (this.tag(extra, i)) {
                    inline else => |comptime_tag| @unionInit(Union, @tagName(comptime_tag), @fromBackingInt(@intCast(elem))),
                };
            }

            /// Valid to call only when deserializing.
            pub fn tag(this: *const @This(), extra: []const u32, i: usize) Tag {
                const start = @intFromPtr(this.data);
                const meta_start = start - (this.len * @bitSizeOf(Meta) + 31) / 32;
                return loadBits(u32, extra[meta_start..], i * @bitSizeOf(Meta), Meta).tag;
            }

            fn extraLen(len: usize) usize {
                return len + (len * @bitSizeOf(Meta) + 31) / 32;
            }
        };
    }