Commit 3c8d968194

ominitay <37453713+ominitay@users.noreply.github.com>
2022-07-31 23:58:04
fmt: Make default_max_depth configurable
1 parent 2ccff51
Changed files (2)
lib/std/fmt.zig
@@ -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;
@@ -190,7 +191,7 @@ pub fn format(
                 .precision = precision,
             },
             writer,
-            default_max_depth,
+            std.options.fmt_max_depth,
         );
     }
 
@@ -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"));
     }
 }
lib/std/std.zig
@@ -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