authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-21 21:14:11 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-21 21:14:11 -07:00
logee0eea0148421042c4a87141aa4a3cedee7048a1
tree029dc24c782ecca9858db09a6b73bdc741d7099c
parentf19055bc604f023b8bea0283b1f8b595161c4cf3

rework format to not need allocator


1 files changed, 6 insertions(+), 2 deletions(-)

ulid.zig+6-2
...@@ -54,9 +54,13 @@ pub const ULID = struct {...@@ -54,9 +54,13 @@ pub const ULID = struct {
54 pub const fromString = readField;54 pub const fromString = readField;
55 pub const toString = bindField;55 pub const toString = bindField;
5656
57 pub fn format(self: ULID, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) @TypeOf(writer).Error!void {57 pub fn format(self: ULID, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
58 _ = fmt;58 _ = fmt;
59 _ = options;59 _ = options;
60 try writer.writeAll(self.toString());60
61 var buf: [26]u8 = undefined;
62 base32.formatInt(u48, self.timestamp, buf[0..10]);
63 base32.formatInt(u80, self.randomnes, buf[10..26]);
64 try writer.writeAll(&buf);
61 }65 }
62};66};