Skip to main content

Module uuid

Module uuid 

Source
Expand description

UUID — a 128-bit universally-unique identifier (RFC 9562, superseding RFC 4122).

Rolled in-house rather than wrapping a crate: the campaign builds first-class types, and owning the implementation is what lets us be byte-exact across every tier and benchmark it head-to-head. The value is a fixed [u8; 16] in network (big-endian) byte order, so it is Copy, Ord by bytes (which makes v6/v7 time-ordered ids sort chronologically), and hashes cheaply.

Every standard version is here:

  • nil (all-zero) and max (all-one) — the two special ids.
  • v1 (gregorian time + node) and v6 (the same fields reordered to sort by time).
  • v3 (MD5 of namespace ‖ name) and v5 (SHA-1 of namespace ‖ name) — name-based, stable.
  • v4 (random) and v7 (Unix-millis time-ordered + random) — the two you reach for today.
  • v8 (free-form / vendor-defined) — arbitrary bytes with the version+variant bits stamped.

Generation takes the entropy/time as parameters (no ambient clock or RNG here) so it is pure and deterministic — the higher tiers seed it for byte-identical cross-tier output. Validated against the uuid crate (the name-based and random/time builders, parse, and display) in the tests.

Structs§

Uuid
A 128-bit UUID, stored big-endian (RFC 9562 byte order).

Enums§

Variant
The RFC-defined variant of a UUID — which layout the variant/version bits follow.

Functions§

encode_canonical
Write a UUID’s canonical 36-byte text into a caller buffer (no allocation) — the alloc-free hot path for Display and for BULK formatting (fill one big buffer, zero per-id allocations). Uses an SSSE3 pshufb nibble→hex encode when available, else the byte-pair table.
encode_many
Format many UUIDs into ONE contiguous buffer (each 36 bytes, \n-free), zero per-id allocation — the bulk path a database column / log stream wants. Returns the packed 36·n-byte buffer.