| Crates.io | uniqer_rs |
| lib.rs | uniqer_rs |
| version | 0.0.4 |
| created_at | 2025-09-03 12:19:22.038946+00 |
| updated_at | 2025-09-03 12:52:36.358521+00 |
| description | A simple and flexible library for generating various types of unique IDs using a builder pattern. |
| homepage | |
| repository | https://github.com/hamzaelmarjani/uniqer_rs |
| max_upload_size | |
| id | 1822442 |
| size | 39,226 |
uniqer_rs is a lightweight and easy-to-use Rust library for generating various types of unique identifiers. It provides a simple builder-pattern API for creating random alphanumeric, numeric, and alphabetic IDs, as well as standard UUIDs (v1, v4, and v7).
Uniqer::new().method()Add uniqer_rs to your Cargo.toml file:
[dependencies]
uniqer_rs = "0.0.4"
Here are some examples of how to use uniqer. All length-based methods return a Result<String, UniqerError>.
use uniqer_rs::{Uniqer, UniqerError};
fn main() -> Result<(), UniqerError> {
// 1. Alphanumeric ID (letters + numbers), custom length is 16
let id = Uniqer::new().with_length(16).unique_id()?;
println!("Alphanumeric ID: {}", id);
// Alphanumeric ID: mOvDUPUi5u6Ub18B
// 2. Numeric-only ID
let num_id = Uniqer::new().unique_number()?;
println!("Numeric ID: {}", num_id);
// Numeric ID: 790505571683
// 3. Alphabetic-only ID (no numbers)
let text_id = Uniqer::new().unique_id_no_numbers()?;
println!("Alphabetic ID: {}", text_id);
// Alphabetic ID: jvlpwOiWoveB
// 4. UUID v1 (time-based)
let uuid_v1 = Uniqer::new().uuidv1()?;
println!("UUID v1: {}", uuid_v1);
// UUID v1: 5ec88532-88c4-11f0-8000-9b32f2282b2c
// 5. UUID v4 (random)
let uuid_v4 = Uniqer::new().uuidv4()?;
println!("UUID v4: {}", uuid_v4);
// UUID v4: 1c7cea27-e925-4760-9788-6b3665063afc
// 6. UUID v7 (time-based, sortable)
let uuid_v7 = Uniqer::new().uuidv7()?;
println!("UUID v7: {}", uuid_v7);
// UUID v7: 01990f9f-9f85-7d00-be59-beab14532984
Ok(())
}
If you request an ID with a length shorter than 8 characters, the methods will return an error, just to ensure the ID is unique.
use uniqer_rs::{Uniqer, UniqerError};
fn main() {
let result = Uniqer::new().width_length(5).unique_id();
match result {
Ok(id) => println!("Generated ID: {}", id),
Err(UniqerError::LengthTooShort(len)) => {
eprintln!("Error: Requested length {} is too short. Minimum is 8.", len);
}
}
}
# Run the unique_ids
cargo run --example unique_ids
| Method | Description |
|---|---|
Uniquer::new() |
Create Uniquer instance (required)* |
.with_length(usize) |
specify the length of the id, min 8 (optional)* |
.unique_id() |
Alphanumeric ID (letters + numbers) |
.unique_number() |
Numeric-only ID |
.unique_id_no_numbers() |
Alphabetic-only ID (no numbers) |
.uuidv1() |
UUID v1 (time-based) |
.uuidv4() |
UUID v4 (random) |
.uuidv7() |
UUID v7 (time-based, sortable) |
The crate uses standard Rust error handling patterns. All async methods return Result types:
match Uniquer::new().unique_id() {
Ok(id) => println!("Unique ID: {}", id),
Err(e) => eprintln!("Error generation ID: {}", e),
}
Licensed under either of:
at your option.
Contributions are welcome! Please feel free to:
Before contributing, please ensure your code follows Rust conventions and includes appropriate tests.
If you like this project, consider supporting me on Patreon 💖
See CHANGELOG.md for a detailed history of changes.