shortid-rs
Generate short, human-friendly IDs derived from UUIDs with collision handling.
Great for games, simulations, or any system where raw UUIDs are too long and ugly to show users.
✨ Features
- Deterministically derive a short ID from a UUID.
- Compact 6-char Base62 encoding (A–Z, a–z, 0–9).
- Collision handling with automatic
-or_insertion (never first or last). - Fast: ~1µs per ID generation in benchmarks.
- Keeps full UUIDs as primary keys internally; short IDs are for human use.
📦 Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
= { = "1", = ["v4"] }
🚀 Usage
use ;
use Uuid;
use HashSet;
Example output:
UUID: 550e8400-e29b-41d4-a716-446655440000 -> Short ID: Ab9xQ2
Deterministic short code: Ab9xQ2
🧪 Tests
Run the built-in tests:
Or run integration tests in the tests/ folder:
📊 Benchmarks
Benchmarks are provided with Criterion.rs.
Example result:
generate_short_code time: [911.40 ns 1.38 µs 2.40 µs]
⚖️ License
MIT License. See LICENSE for details.