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.

addExtra

Parse.addExtra
fn addExtra(p: *Parse, extra: anytype) Allocator.Error!ExtraIndex

File

lib/std/zig/Parse.zig:105

Code

fn addExtra(p: *Parse, extra: anytype) Allocator.Error!ExtraIndex {
    const info = @typeInfo(@TypeOf(extra)).@"struct";
    try p.extra_data.ensureUnusedCapacity(p.gpa, info.field_names.len);
    const result: ExtraIndex = @fromBackingInt(@intCast(p.extra_data.items.len));
    inline for (info.field_names, info.field_types) |field_name, field_type| {
        const data: u32 = switch (field_type) {
            Node.Index,
            Node.OptionalIndex,
            OptionalTokenIndex,
            ExtraIndex,
            => @backingInt(@field(extra, field_name)),
            TokenIndex,
            => @field(extra, field_name),
            else => @compileError("unexpected field type"),
        };
        p.extra_data.appendAssumeCapacity(data);
    }
    return result;
}