Returns the requested data, as well as the new index which is at the start of the trailers for the object.
fn extraData(eb: ErrorBundle, comptime T: type, index: usize) struct
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,
};
}