core:uuid
UUID generation and parsing (RFC 9562).
Only the two versions in common use today are provided:
Uuid::v4()— random UUID. The default for "just give me a unique id".Uuid::v7()— time-ordered UUID. A 48-bit Unix-millisecond timestamp in the high bytes makes values sortable by creation time, which is ideal for database keys and log correlation.
A Uuid is a single 128-bit value (stored as a u8x16 SIMD register, one
lane per byte). Construction, formatting, and parsing are all byte-oriented,
which maps directly onto the lane layout. Equality and ordering compare the
16 bytes in big-endian order, so v7 values sort by timestamp.
Uuid::v4() needs Random; Uuid::v7() needs Random and SystemClock.
parse accepts both the hyphenated form and the 32-digit hyphenless
"simple" form, matching Rust's uuid and Go's google/uuid.
Synopsis
assert Uuid::parse(&"550e8400-e29b-41d4-a716-446655440000") matches { Some(id) && id.version() == 4
&& id.to_string() == "550e8400-e29b-41d4-a716-446655440000" };
Structs
pub struct Uuid
A 128-bit universally unique identifier.
The bytes are held big-endian: byte 0 is the most significant. This is the
order RFC 9562 lays out the fields in, so the natural byte order is also the
canonical string order and (for v7) the timestamp order.
Fields are private.
pub fn nil() -> Uuid
The nil UUID — all 128 bits zero (00000000-0000-0000-0000-000000000000).
pub fn v4() -> Uuid with Random
Generate a version-4 (random) UUID.
All 122 free bits come from the cryptographically-secure Random
effect; the version (0100) and variant (10) bits are then forced
into place per RFC 9562.
pub fn v7() -> Uuid with Random, SystemClock
Generate a version-7 (time-ordered) UUID.
The high 48 bits are the Unix timestamp in milliseconds, read from the
SystemClock effect; the remaining bits are random. Because the
timestamp occupies the most significant bytes, lexicographic / numeric
ordering of v7 values matches creation-time ordering.
pub fn parse(s: &String) -> Option<Uuid>
Parse a UUID string (case-insensitive), like Rust's uuid and Go's
google/uuid:
- the canonical hyphenated form
8-4-4-4-12(36 chars), with hyphens required at exactly the field boundaries, or - the simple form: 32 hex digits with no hyphens.
Returns null for anything else.
pub fn version(&self) -> i32
The version number (4 or 7 for UUIDs produced by this module).
pub fn to_string(&self) -> String
The canonical hyphenated lowercase string form.
