Skip to content

@uuid

Import this module with import @uuid.

UUID is an opaque struct type (see Keywords) with no user-visible fields; printing a UUID value directly does not yield its hyphenated string form. Call to_string() to get the canonical 36-character hyphenated string. All generator and parse functions return UUID.

Function Signature Description
generate () -> UUID Generate UUID v4 (hyphenated, 36 chars)
generate_random () -> UUID RFC 4122 v4 (random), hyphenated, lowercase
generate_time_ordered () -> UUID RFC 9562 v7 (time-ordered), hyphenated, lowercase. Sorts by creation time
generate_v5 (namespace UUID, name string) -> UUID Deterministic RFC 4122 v5 (name-based, SHA-1)
generate_compact (id UUID) -> string Strip hyphens from a UUID, returning a 32-char hex string
parse (s string) -> UUID Validate and normalize a 36-char hyphenated UUID to lowercase. Panics on invalid input — gate with is_valid() for a non-panicking check
to_string (id UUID) -> string Convert UUID to its 36-char hyphenated string representation
to_bytes (id UUID) -> [u8] The 16 raw bytes, big-endian order
from_bytes (bytes [u8]) -> UUID Build a UUID from 16 raw bytes, verbatim. Panics if fewer than 16
version (id UUID) -> i64 The version nibble (1–8); 0 for the nil UUID
timestamp (id UUID) -> (i64, bool) Embedded creation time as Unix ms; the bool is true only for v1/v7 — always destructure
is_valid (s string) -> bool Validate UUID format
Constant Type Value
NIL_UUID UUID All-zero UUID (00000000-0000-0000-0000-000000000000)

UUID randomness comes from getentropy() (macOS, BSDs, glibc 2.25+) with a fallback to /dev/urandom, suitable for security-sensitive identifiers.