diff --git a/ulid.zig b/ulid.zig index 2b54d654fc149f2d9f76816123ad86853cc8a189..71ef3b997d91e5dc3a8be05dc142f3924bca1f83 100644 --- a/ulid.zig +++ b/ulid.zig @@ -56,13 +56,16 @@ pub const ULID = struct { pub const readField = parse; pub const bindField = toString; - pub fn format(self: ULID, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void { - _ = fmt; - _ = options; - + pub fn bytes(self: ULID) [26]u8 { 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); + return buf; + } + + pub fn format(self: ULID, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void { + _ = fmt; + _ = options; + try writer.writeAll(&self.bytes()); } };