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.

printStructValue

Options.printStructValue
fn printStructValue(
    options: *Options,
    out: *std.ArrayList(u8),
    comptime struct_val: std.builtin.Type.Struct,
    val: anytype,
    indent: u8,
) !void

File

lib/std/Build/Step/Options.zig:382

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");
    }
}