Skip to content

Commit 4780cc5

Browse files
tiehuisandrewrk
authored andcommitted
std.Io.Writer: support alignment for {t} specifier
1 parent e43617e commit 4780cc5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/std/Io/Writer.zig

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,8 +1123,8 @@ pub fn printValue(
11231123
else => invalidFmtError(fmt, value),
11241124
},
11251125
't' => switch (@typeInfo(T)) {
1126-
.error_set => return w.writeAll(@errorName(value)),
1127-
.@"enum", .@"union" => return w.writeAll(@tagName(value)),
1126+
.error_set => return w.alignBufferOptions(@errorName(value), options),
1127+
.@"enum", .@"union" => return w.alignBufferOptions(@tagName(value), options),
11281128
else => invalidFmtError(fmt, value),
11291129
},
11301130
else => {},
@@ -2134,6 +2134,14 @@ test "bytes.hex" {
21342134
try testing.expectFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", .{bytes_with_zeros});
21352135
}
21362136

2137+
test "padding" {
2138+
const foo: enum { foo } = .foo;
2139+
try testing.expectFmt("tag: |foo |\n", "tag: |{t:<4}|\n", .{foo});
2140+
2141+
const bar: error{bar} = error.bar;
2142+
try testing.expectFmt("error: |bar |\n", "error: |{t:<4}|\n", .{bar});
2143+
}
2144+
21372145
test fixed {
21382146
{
21392147
var buf: [255]u8 = undefined;

0 commit comments

Comments
 (0)