UUID in Rust: uuid Crate for Generating and Parsing
Generate UUIDs in Rust with the uuid crate. Enable v4, v7 features, parse UUID strings, and use UUIDs as primary keys in Diesel and SQLx.
Published:
Tags: developer-tools, uuid, rust
UUID in Rust: uuid Crate Guide for Generating and Parsing UUIDs The crate is the standard for UUID handling in Rust. It provides a type that is zero-overhead compared to storing a UUID as a — 16 bytes on the stack, no heap allocation, and full compile-time type safety. Here is how to use it effectively including Diesel and SQLx integration. --- Setup The crate uses feature flags to keep the binary small. Enable only what you need: Feature flags: | Feature | Enables | |---------|---------| | | UUID v1 (timestamp + node) | | | UUID v3 (MD5 namespace) | | | UUID v4 (random) | | | UUID v5 (SHA-1 namespace) | | | UUID v6 (reordered timestamp) | | | UUID v7 (Unix timestamp, sortable) | | | Serde serialisation/deserialisation | | | Faster but not cryptographically secure RNG | For most projects:…
All articles · theproductguy.in