- Tools for generating uuids
Best lib: uuid crate
Pro
: serde friendlyPro
: modular (see crate features)Pro
: Some official support from the rust teamPro
: Actively developedPro
: Popular
- Add to your
Cargo.toml
fast-rng
feature is faster, but uses more external crates (dependencies)
// -- Generate random
let value = Uuid::new_v4();
// -- Parse at runtime
let value = Uuid::parse_str("c4c4075f-c17f-49ea-aec9-b45d697aa431")?;
// -- Parse at compile time (constant)
const MY_VALUE: Uuid = uuid!("92153ec4-b5e9-46e4-9935-df36b2cd4f4b");
Rust | Java |
---|---|
Uuid::new_v4() |
UUID.randomUUID() |
Uuid::parse_str(...) |
UUID.fromString(...) |