feature. See also
. The project being documented here (as the example) is the Zig library itself.
Options.printEnum
fn printEnum(
options: *Options,
out: *std.ArrayList(u8),
comptime T: type,
comptime val: std.builtin.Type.Enum,
indent: u8,
) !void
File
Code
fn printEnum(
options: *Options,
out: *std.ArrayList(u8),
comptime T: type,
comptime val: std.builtin.Type.Enum,
indent: u8,
) !void {
const gpa = options.step.owner.allocator;
const gop = try options.encountered_types.getOrPut(gpa, @typeName(T));
if (gop.found_existing) return;
try out.appendNTimes(gpa, ' ', indent);
try out.print(gpa, "pub const {f} = enum ({s}) {{\n", .{ std.zig.fmtId(@typeName(T)), @typeName(val.tag_type) });
inline for (val.field_names, val.field_values) |field_name, field_value| {
try out.appendNTimes(gpa, ' ', indent);
try out.print(gpa, " {f} = {d},\n", .{
std.zig.fmtIdFlags(field_name, .{ .allow_primitive = true }), field_value,
});
}
if (val.mode == .nonexhaustive) {
try out.appendNTimes(gpa, ' ', indent);
try out.appendSlice(gpa, " _,\n");
}
try out.appendNTimes(gpa, ' ', indent);
try out.appendSlice(gpa, "};\n");
}