From ee0eea0148421042c4a87141aa4a3cedee7048a1 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Thu, 21 Oct 2021 21:14:11 -0700 Subject: [PATCH] rework format to not need allocator --- ulid.zig | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ulid.zig b/ulid.zig index c8c10e60c0f5412cda33f5bdc1a689f98bc73896..de000254341408e7be3d4fd5b19213e129b8509b 100644 --- a/ulid.zig +++ b/ulid.zig @@ -54,9 +54,13 @@ pub const ULID = struct { pub const fromString = readField; pub const toString = bindField; - pub fn format(self: ULID, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) @TypeOf(writer).Error!void { + pub fn format(self: ULID, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void { _ = fmt; _ = options; - try writer.writeAll(self.toString()); + + var buf: [26]u8 = undefined; + base32.formatInt(u48, self.timestamp, buf[0..10]); + base32.formatInt(u80, self.randomnes, buf[10..26]); + try writer.writeAll(&buf); } }; -- 2.54.0