| ... | @@ -56,13 +56,16 @@ pub const ULID = struct { | ... | @@ -56,13 +56,16 @@ pub const ULID = struct { |
| 56 | pub const readField = parse; | 56 | pub const readField = parse; |
| 57 | pub const bindField = toString; | 57 | pub const bindField = toString; |
| 58 | | 58 | |
| 59 | pub fn format(self: ULID, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void { | 59 | pub fn bytes(self: ULID) [26]u8 { |
| 60 | _ = fmt; | | |
| 61 | _ = options; | | |
| 62 | | | |
| 63 | var buf: [26]u8 = undefined; | 60 | var buf: [26]u8 = undefined; |
| 64 | base32.formatInt(u48, self.timestamp, buf[0..10]); | 61 | base32.formatInt(u48, self.timestamp, buf[0..10]); |
| 65 | base32.formatInt(u80, self.randomnes, buf[10..26]); | 62 | base32.formatInt(u80, self.randomnes, buf[10..26]); |
| 66 | try writer.writeAll(&buf); | 63 | return buf; |
| | 64 | } |
| | 65 | |
| | 66 | pub fn format(self: ULID, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void { |
| | 67 | _ = fmt; |
| | 68 | _ = options; |
| | 69 | try writer.writeAll(&self.bytes()); |
| 67 | } | 70 | } |
| 68 | }; | 71 | }; |