Expand description
A tiny crate for generating short, URL-safe, unique identifiers.
Unlike full UUIDs (which are 36 characters and include hyphens), short-id gives you
compact 14-character strings that are easy to copy, paste, and use in URLs.
§Goals
-
Make it very easy to generate short random IDs for things like request IDs, user-facing tokens, test data, and log correlation.
-
Provide an optional “ordered” variant where IDs include a timestamp prefix, so when you sort them as strings they roughly follow creation time.
This crate is intentionally minimal - no configuration, no custom alphabets, no complex API.
§Quick Start
use short_id::short_id;
// Generate a random ID
let id = short_id();
println!("Request ID: {}", id);
// Example output: "X7K9mP2nQwE-Tg"For time-ordered IDs:
use short_id::short_id_ordered;
let id1 = short_id_ordered();
std::thread::sleep(std::time::Duration::from_millis(100));
let id2 = short_id_ordered();
// IDs from different times are different
assert_ne!(id1, id2);§Use Cases
- Request IDs for logging and tracing
- User-facing tokens and session IDs
- Test data generation
- Short URLs and resource identifiers
- Any place you want something shorter and simpler than UUIDs
§Characteristics
- Length: Always exactly 14 characters
- URL-safe: Only
A-Z,a-z,0-9,-,_(no special characters) - Cryptographically secure: Uses
OsRngfor random bytes - No configuration needed: Just call the function
§Features
std(enabled by default): Enablesshort_id_ordered()which needsstd::time::SystemTime
For no_std environments with alloc:
[dependencies]
short-id = { version = "0.1", default-features = false }In no_std mode, only short_id() is available.
Functions§
- short_
id - Generates a random, URL-safe short ID.
- short_
id_ ordered - Generates a time-ordered, URL-safe short ID.