Parse and generate version 4 and version 7 UUIDs.
const uuid1 = zul.UUID.v4();
const hex = uuid1.toHex(.lower);
const uuid2 = try zul.UUID.parse("761e3a9d-4f92-4e0d-9d67-054425c2b5c3");
std.debug.print("{any}\n", uuid1.eql(uuid2));
const uuid3 = zul.UUID.v7();
try std.json.stringify(.{.id = uuid3}, .{}, writer);
zul.UUID
is a thin wrapper around a [16]u8
. Its main purpose is to generate a hex-encoded version of the UUID.
bin: [16]u8
The binary representation of the UUID.
UUID.v4() UUID
Generate a version 4 (random) UUID.
UUID.v7() UUID
Generate a version 7 UUID.
UUID.random() UUID
Non-compliant pseudo-UUID. Does not have a version or variant. Use UUID.v4() or UUID.v7() unless you have specific reasons not to.
UUID.parse(hex: []const u8) !UUID
Attempts to parse a hex-encoded UUID. Returns error.InvalidUUID
is the UUID is not valid.
UUID.bin2Hex(bin: []const u8, case: Case) ![36]iu8
Hex encodes a 16 byte binary UUID.
toHex(uuid: UUID, case: Case) [36]u8
Hex-encodes the UUID. The case
parameter must be .lower
or .upper
and controls whether lowercase or uppercase hexadecimal is used.
This method should be preferred over the other toHex*
variants.