Crates.io | shortid-rs |
lib.rs | shortid-rs |
version | 0.1.0 |
created_at | 2025-09-18 03:57:08.253717+00 |
updated_at | 2025-09-18 03:57:08.253717+00 |
description | Generate short, human-friendly IDs derived from UUIDs with collision handling. |
homepage | |
repository | https://github.com/JDPlumbing/shortid-rs |
max_upload_size | |
id | 1844225 |
size | 30,045 |
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.
-
or _
insertion (never first or last).Add this to your Cargo.toml
:
[dependencies]
shortid-rs = "0.1.0"
uuid = { version = "1", features = ["v4"] }
use shortid_rs::{short_code_from_uuid, unique_short_code};
use uuid::Uuid;
use std::collections::HashSet;
fn main() {
let uuid = Uuid::new_v4();
let mut existing = HashSet::new();
let code = unique_short_code(&uuid, &mut existing);
println!("UUID: {} -> Short ID: {}", uuid, code);
let deterministic = short_code_from_uuid(&uuid);
println!("Deterministic short code: {}", deterministic);
}
Example output:
UUID: 550e8400-e29b-41d4-a716-446655440000 -> Short ID: Ab9xQ2
Deterministic short code: Ab9xQ2
Run the built-in tests:
cargo test
Or run integration tests in the tests/
folder:
cargo test --test basic
Benchmarks are provided with Criterion.rs.
cargo bench
Example result:
generate_short_code time: [911.40 ns 1.38 µs 2.40 µs]
MIT License. See LICENSE for details.