Expand description
Universally Unique IDentifiers (RFC 9562).
Supports parsing all versions and generating version 4 (random) and version 7 (Unix-epoch time-based) UUIDs.
Parsing is strict: Uuid::parse accepts only the canonical 8-4-4-4-12
hexadecimal form (lowercase or uppercase). Alternative textual forms such as
the simple (unhyphenated), URN or brace-wrapped representations are
intentionally rejected, which avoids the lax-parsing pitfalls of some other
UUID implementations.
Version 7 UUIDs carry a per-thread monotonic counter. Values produced by a
single thread are strictly increasing; ordering across threads is not
guaranteed. If the system clock moves backwards the generator keeps the last
logical timestamp and advances the counter, so ordering is preserved. See
Uuid::new_v7 for details.
§Feature flags
| Flag | Description | Default |
|---|---|---|
std | Enables Uuid::new_v4 and Uuid::new_v7 via rand | Yes |
serde | Enables serde serialization/deserialization | No |
When std is not enabled, the crate is #![no_std] compatible.
Parsing, formatting, and version detection are all available.
§Example
use uuid::{Uuid, Version};
// Parse a version-4 UUID from its canonical form
let uuid = Uuid::parse("f47ac10b-58cc-4372-a567-0e02b2c3d479").unwrap();
assert_eq!(uuid.version(), Version::V4);
// Format it without allocating
let text = uuid.to_heapless_string();
assert_eq!(text.as_str(), "f47ac10b-58cc-4372-a567-0e02b2c3d479");
// Generate new UUIDs (requires the `std` feature, enabled by default)
let v4 = Uuid::new_v4();
let v7 = Uuid::new_v7();
assert_eq!(v4.version(), Version::V4);
assert_eq!(v7.version(), Version::V7);Structs§
- Uuid
- A 128-bit UUID (RFC 9562).