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.

extraData

Returns the requested data, as well as the new index which is at the start of the trailers for the object.

ErrorBundle.extraData
fn extraData(eb: ErrorBundle, comptime T: type, index: usize) struct

File

lib/std/zig/ErrorBundle.zig:130

Code

fn extraData(eb: ErrorBundle, comptime T: type, index: usize) struct { data: T, end: usize } {
    const field_names = @typeInfo(T).@"struct".field_names;
    const field_types = @typeInfo(T).@"struct".field_types;
    var i: usize = index;
    var result: T = undefined;
    inline for (field_names, field_types) |field_name, field_type| {
        @field(result, field_name) = switch (field_type) {
            u32 => eb.extra[i],
            MessageIndex => @as(MessageIndex, @fromBackingInt(@intCast(eb.extra[i]))),
            SourceLocationIndex => @as(SourceLocationIndex, @fromBackingInt(@intCast(eb.extra[i]))),
            else => @compileError("bad field type"),
        };
        i += 1;
    }
    return .{
        .data = result,
        .end = i,
    };
}