authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-08-10 18:14:33 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-08-10 18:14:33 -07:00
log7f2c7edf0e7f91229be17bda52d0e74d42d862e2
tree1b2b19d8664c4028fed6505437324194999e076c
parentcd3d71e545fc2b69c84e42994c7c95a79884350d

ulid: add bytes() method to get array directly since they are known-size


1 files changed, 8 insertions(+), 5 deletions(-)

ulid.zig+8-5
......@@ -56,13 +56,16 @@ pub const ULID = struct {
5656 pub const readField = parse;
5757 pub const bindField = toString;
5858
59 pub fn format(self: ULID, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
60 _ = fmt;
61 _ = options;
62
59 pub fn bytes(self: ULID) [26]u8 {
6360 var buf: [26]u8 = undefined;
6461 base32.formatInt(u48, self.timestamp, buf[0..10]);
6562 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());
6770 }
6871};