Skip to content

UUID

The core UUID type.

Definition

zig
pub const UUID = struct {
    bytes: [16]u8,
    // ...
};

Fields

FieldTypeDescription
bytes[16]u8Raw 16-byte UUID representation

Constants

ConstantDescription
UUID.nilThe zero UUID
UUID.maxThe max UUID (ffffffff-ffff-ffff-ffff-ffffffffffff)

Methods

Generation

MethodSignatureDescription
v1(timestamp: u60, clock_seq: u14, node_id: [6]u8) UUIDTime-based
v2(domain: u8, local_id: u32, node_id: [6]u8) UUIDDCE Security (POSIX UID/GID)
v3(namespace: UUID, name: []const u8) UUIDMD5 namespace
v4(io: Io) Io.RandomSecureError!UUIDRandom
v5(namespace: UUID, name: []const u8) UUIDSHA-1 namespace
v6(timestamp: u60, clock_seq: u14, node_id: [6]u8) UUIDReordered time
v7(timestamp_ms: u48, rand_a: u12, rand_b: [10]u8) UUIDEpoch time
v7Now(io: Io) Io.RandomSecureError!UUIDv7 with current time
v8(custom: [16]u8) UUIDApplication-specific

Formatting

MethodSignatureDescription
encode(self, buffer: []u8) []u8Canonical format
encodeUppercase(self, buffer: []u8) []u8Uppercase format
encodeCompact(self, buffer: []u8) []u8Compact format
encodeBraced(self, buffer: []u8) []u8Braced format
encodeUrn(self, buffer: []u8) []u8URN format
format(self, writer: *Io.Writer) Io.Writer.Error!voidWrite to writer
toString(self, allocator: Allocator) Allocator.Error![]u8Allocated string

Inspection

MethodSignatureDescription
version(self) VersionGet version
variant(self) VariantGet variant
isNil(self) boolCheck if nil
isMax(self) boolCheck if max UUID
hash(self) u64Get hash

Component Extraction

MethodSignatureDescription
timestampV1(self) u60Extract timestamp from v1 UUID
timestampV6(self) u60Extract timestamp from v6 UUID
timestampV7(self) u48Extract millisecond timestamp from v7 UUID
clockSeq(self) u14Extract clock sequence from v1/v6 UUID
node(self) [6]u8Extract node from v1/v6 UUID

Comparison

MethodSignatureDescription
eql(self, other: UUID) boolEquality
compare(self, other: UUID) std.math.OrderOrdering

Conversion

MethodSignatureDescription
toBytes(self) [16]u8Convert to bytes
fromBytes(bytes: [16]u8) UUIDCreate from bytes (static)
toU128(self) u128Convert to u128
fromU128(value: u128) UUIDCreate from u128 (static)

Sorting

MethodSignatureDescription
sort(uuids: []UUID) voidSort UUIDs in-place (static)

Hash Generation

MethodSignatureDescription
generateFromHash(ver: Version, namespace: *const [16]u8, name: []const u8) UUIDHash-based generation

Module Functions

FunctionSignatureDescription
isValid(input: []const u8) boolValidate UUID string format

Released under the MIT License.