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, ideal for database keys and log correlation.
Uuid::v4() needs Random; Uuid::v7() needs Random and SystemClock.
Generating in bulk, run it under core:secure_random's with_buffered so
the host call is drawn once per block rather than once per UUID.
FromStr accepts the four forms Rust's uuid and Go's uuid do. Display
and Inspect render the canonical hyphenated form, as does Serialize for
text formats; binary ones get CBOR tag 37 and the 16 bytes.
v7 sorts by creation time under RFC 9562 method 3: the timestamp leads the
bytes, rand_a holding its sub-millisecond fraction, one tick per 244 ns.
Values within a tick, or across a backwards clock step, are unordered.
Synopsis
assert Uuid::from_str("550e8400-e29b-41d4-a716-446655440000") matches { Ok(id) && id.version() == 4
&& id.to_string() == "550e8400-e29b-41d4-a716-446655440000" };
Structs
pub struct Uuid
A 128-bit universally unique identifier, held big-endian as RFC 9562 lays the fields out.
Fields are private.
pub fn nil() -> Uuid
The nil UUID — all 128 bits zero (00000000-0000-0000-0000-000000000000).
pub fn max() -> Uuid
The max UUID — all 128 bits one (ffffffff-ffff-ffff-ffff-ffffffffffff).
pub fn v4() -> Uuid with Random
Generate a version-4 (random) UUID: 122 bits from Random, with the
RFC 9562 version and variant bits forced into place.
pub fn v7() -> Uuid with (Random, SystemClock)
Generate a version-7 (time-ordered) UUID: a 48-bit millisecond timestamp
and a 12-bit sub-millisecond fraction from SystemClock, then 62
random bits.
pub fn from_bytes(bytes: &ByteList) -> Option<Uuid>
Build a UUID from its 16 big-endian bytes. null for any other length.
pub fn as_bytes(&self) -> ByteList
The 16 bytes, most significant first.
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.
impl FromStr for Uuid
fn from_str<S: AsStrSlice>(s: S) -> Result<Uuid, ParseError>
impl Display for Uuid
fn fmt(&self, f: &mut Formatter)
impl Inspect for Uuid
pub fn inspect(&self, f: &mut Formatter)
impl Serialize for Uuid
fn serialize<S: Serializer>(&self, s: &mut S) -> Result<(), SerializeError>
impl Deserialize for Uuid
fn deserialize<D: Deserializer>(d: &mut D) -> Result<Uuid, DeserializeError>
impl Eq for Uuid
fn eq(&self, other: &Uuid) -> bool
impl Ord for Uuid
fn cmp(&self, other: &Uuid) -> Ordering
impl Default for Uuid
fn default() -> Uuid
Variants
pub variant ParseError
Why a string was not a UUID.
InvalidLength
Not 32, 36, 38 (braced) or 45 (URN) characters long.
InvalidGroups
Hyphens, braces or the urn:uuid: prefix are not where they belong.
