Commit 4780cc50cf

Marc Tiehuis <marc@tiehu.is>
2025-07-20 03:57:31
std.Io.Writer: support alignment for `{t}` specifier
1 parent e43617e
Changed files (1)
lib
std
lib/std/Io/Writer.zig
@@ -1123,8 +1123,8 @@ pub fn printValue(
                 else => invalidFmtError(fmt, value),
             },
             't' => switch (@typeInfo(T)) {
-                .error_set => return w.writeAll(@errorName(value)),
-                .@"enum", .@"union" => return w.writeAll(@tagName(value)),
+                .error_set => return w.alignBufferOptions(@errorName(value), options),
+                .@"enum", .@"union" => return w.alignBufferOptions(@tagName(value), options),
                 else => invalidFmtError(fmt, value),
             },
             else => {},
@@ -2134,6 +2134,14 @@ test "bytes.hex" {
     try testing.expectFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", .{bytes_with_zeros});
 }
 
+test "padding" {
+    const foo: enum { foo } = .foo;
+    try testing.expectFmt("tag: |foo |\n", "tag: |{t:<4}|\n", .{foo});
+
+    const bar: error{bar} = error.bar;
+    try testing.expectFmt("error: |bar |\n", "error: |{t:<4}|\n", .{bar});
+}
+
 test fixed {
     {
         var buf: [255]u8 = undefined;