feature. See also
. The project being documented here (as the example) is the Zig library itself.
Options.printStructValue
fn printStructValue(
options: *Options,
out: *std.ArrayList(u8),
comptime struct_val: std.builtin.Type.Struct,
val: anytype,
indent: u8,
) !void
File
Code
fn printStructValue(
options: *Options,
out: *std.ArrayList(u8),
comptime struct_val: std.builtin.Type.Struct,
val: anytype,
indent: u8,
) !void {
const gpa = options.step.owner.allocator;
try out.appendSlice(gpa, ".{\n");
if (struct_val.is_tuple) {
inline for (struct_val.field_names) |field_name| {
try out.appendNTimes(gpa, ' ', indent);
try printType(options, out, @TypeOf(@field(val, field_name)), @field(val, field_name), indent, null);
}
} else {
inline for (struct_val.field_names) |field_name| {
try out.appendNTimes(gpa, ' ', indent);
try out.print(gpa, " .{f} = ", .{
std.zig.fmtIdFlags(field_name, .{ .allow_primitive = true, .allow_underscore = true }),
});
const field_val = @field(val, field_name);
switch (@typeInfo(@TypeOf(field_val))) {
.@"enum" => try out.print(gpa, ".{s},\n", .{@tagName(field_val)}),
.@"struct" => |struct_info| {
try printStructValue(options, out, struct_info, field_val, indent + 4);
},
else => try printType(options, out, @TypeOf(field_val), field_val, indent, null),
}
}
}
if (indent == 0) {
try out.appendSlice(gpa, "};\n");
} else {
try out.appendNTimes(gpa, ' ', indent);
try out.appendSlice(gpa, "},\n");
}
}