aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorA cursed quail <quail@cursedquail.com>2025-07-26 10:32:17 -0500
committerAndrew Kelley <andrew@ziglang.org>2025-07-26 21:53:23 -0700
commite12dc4947c411d25c4c56d887e62d0e2b9addcb8 (patch)
treee73d52a1bac71cbaa710951f6c04caa3dde4e457 /lib/std
parent04614d6ea17fff69ead42223c35a257da25462de (diff)
downloadzig-e12dc4947c411d25c4c56d887e62d0e2b9addcb8.tar.gz
zig-e12dc4947c411d25c4c56d887e62d0e2b9addcb8.zip
std.zig: fmtId returns a FormatId
Changes fmtId to return the FormatId type directly, and renames the FormatId.render function to FormatId.format, so it can be used in a format expression directly. Why? Since `render` is private, you can't create functions that wrap `fmtId` or `fmtIdFlags`, since you can't name the return type of those functions outside of std itself. The current setup _might_ be intentional? In which case I can live with it, but I figured I'd make a small contrib to upstream zig :)
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/zig.zig18
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/std/zig.zig b/lib/std/zig.zig
index 2039a4d8c0..a692a63795 100644
--- a/lib/std/zig.zig
+++ b/lib/std/zig.zig
@@ -385,23 +385,23 @@ pub fn serializeCpuAlloc(ally: Allocator, cpu: std.Target.Cpu) Allocator.Error![
/// Return a Formatter for a Zig identifier, escaping it with `@""` syntax if needed.
///
/// See also `fmtIdFlags`.
-pub fn fmtId(bytes: []const u8) std.fmt.Formatter(FormatId, FormatId.render) {
- return .{ .data = .{ .bytes = bytes, .flags = .{} } };
+pub fn fmtId(bytes: []const u8) FormatId {
+ return .{ .bytes = bytes, .flags = .{} };
}
/// Return a Formatter for a Zig identifier, escaping it with `@""` syntax if needed.
///
/// See also `fmtId`.
-pub fn fmtIdFlags(bytes: []const u8, flags: FormatId.Flags) std.fmt.Formatter(FormatId, FormatId.render) {
- return .{ .data = .{ .bytes = bytes, .flags = flags } };
+pub fn fmtIdFlags(bytes: []const u8, flags: FormatId.Flags) FormatId {
+ return .{ .bytes = bytes, .flags = flags };
}
-pub fn fmtIdPU(bytes: []const u8) std.fmt.Formatter(FormatId, FormatId.render) {
- return .{ .data = .{ .bytes = bytes, .flags = .{ .allow_primitive = true, .allow_underscore = true } } };
+pub fn fmtIdPU(bytes: []const u8) FormatId {
+ return .{ .bytes = bytes, .flags = .{ .allow_primitive = true, .allow_underscore = true } };
}
-pub fn fmtIdP(bytes: []const u8) std.fmt.Formatter(FormatId, FormatId.render) {
- return .{ .data = .{ .bytes = bytes, .flags = .{ .allow_primitive = true } } };
+pub fn fmtIdP(bytes: []const u8) FormatId {
+ return .{ .bytes = bytes, .flags = .{ .allow_primitive = true } };
}
test fmtId {
@@ -447,7 +447,7 @@ pub const FormatId = struct {
};
/// Print the string as a Zig identifier, escaping it with `@""` syntax if needed.
- fn render(ctx: FormatId, writer: *Writer) Writer.Error!void {
+ pub fn format(ctx: FormatId, writer: *Writer) Writer.Error!void {
const bytes = ctx.bytes;
if (isValidId(bytes) and
(ctx.flags.allow_primitive or !std.zig.isPrimitive(bytes)) and