Skip to content

Commit

Permalink
fmt: Make default_max_depth configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ominitay authored and Vexu committed Feb 1, 2023
1 parent 2ccff51 commit 3c8d968
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/std/fmt.zig
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const std = @import("std.zig");
const builtin = @import("builtin");

const io = std.io;
const math = std.math;
const assert = std.debug.assert;
const mem = std.mem;
const unicode = std.unicode;
const meta = std.meta;
const builtin = @import("builtin");
const errol = @import("fmt/errol.zig");
const lossyCast = std.math.lossyCast;
const expectFmt = std.testing.expectFmt;
Expand Down Expand Up @@ -190,7 +191,7 @@ pub fn format(
.precision = precision,
},
writer,
default_max_depth,
std.options.fmt_max_depth,
);
}

Expand Down Expand Up @@ -2140,15 +2141,15 @@ test "buffer" {
{
var buf1: [32]u8 = undefined;
var fbs = std.io.fixedBufferStream(&buf1);
try formatType(1234, "", FormatOptions{}, fbs.writer(), default_max_depth);
try formatType(1234, "", FormatOptions{}, fbs.writer(), std.options.fmt_max_depth);
try std.testing.expect(mem.eql(u8, fbs.getWritten(), "1234"));

fbs.reset();
try formatType('a', "c", FormatOptions{}, fbs.writer(), default_max_depth);
try formatType('a', "c", FormatOptions{}, fbs.writer(), std.options.fmt_max_depth);
try std.testing.expect(mem.eql(u8, fbs.getWritten(), "a"));

fbs.reset();
try formatType(0b1100, "b", FormatOptions{}, fbs.writer(), default_max_depth);
try formatType(0b1100, "b", FormatOptions{}, fbs.writer(), std.options.fmt_max_depth);
try std.testing.expect(mem.eql(u8, fbs.getWritten(), "1100"));
}
}
Expand Down
5 changes: 5 additions & 0 deletions lib/std/std.zig
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ pub const options = struct {
else
log.defaultLog;

pub const fmt_max_depth = if (@hasDecl(options_override, "fmt_max_depth"))
options_override.fmt_max_depth
else
fmt.default_max_depth;

pub const cryptoRandomSeed: fn (buffer: []u8) void = if (@hasDecl(options_override, "cryptoRandomSeed"))
options_override.cryptoRandomSeed
else
Expand Down

0 comments on commit 3c8d968

Please sign in to comment.