Skip to content

Latest commit

 

History

History
33 lines (25 loc) · 1.27 KB

uuid.md

File metadata and controls

33 lines (25 loc) · 1.27 KB

Overview

  1. Tools for generating uuids

Best lib: uuid crate

  1. Pro: serde friendly
  2. Pro: modular (see crate features)
  3. Pro: Some official support from the rust team
  4. Pro: Actively developed
  5. Pro: Popular

Setup

  1. Add to your Cargo.toml
  2. fast-rng feature is faster, but uses more external crates (dependencies)

Usage

// -- 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");

Java comparison

Rust Java
Uuid::new_v4() UUID.randomUUID()
Uuid::parse_str(...) UUID.fromString(...)