uniqer_rs

Crates.iouniqer_rs
lib.rsuniqer_rs
version0.0.4
created_at2025-09-03 12:19:22.038946+00
updated_at2025-09-03 12:52:36.358521+00
descriptionA simple and flexible library for generating various types of unique IDs using a builder pattern.
homepage
repositoryhttps://github.com/hamzaelmarjani/uniqer_rs
max_upload_size
id1822442
size39,226
Hamza El Marjani (hamzaelmarjani)

documentation

README

uniqer_rs

Crates.io Docs.rs License

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).

Features

  • Generate random alphanumeric IDs of a specified length
  • Generate random numeric-only IDs
  • Generate random alphabetic-only IDs
  • Generate Version 1 (time-based), Version 4 (random), and Version 7 (time-based, sortable) UUIDs
  • Simple, intuitive builder API: Uniqer::new().method()
  • Built-in validation to ensure a minimum ID length of 8, reducing collision probability

Installation

Add uniqer_rs to your Cargo.toml file:

[dependencies]
uniqer_rs = "0.0.4"

Usage

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(())
}

Error Handling

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);
        }
    }
}

Running Examples

# Run the unique_ids
cargo run --example unique_ids

API Overview

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)

Error Handling

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),
}

Requirements

  • Rust 1.57+
  • uuid
  • rand

License

Licensed under either of:

at your option.

Contributing

Contributions are welcome! Please feel free to:

  • Open issues for bugs or feature requests
  • Submit pull requests with improvements
  • Improve documentation or examples
  • Add tests or benchmarks

Before contributing, please ensure your code follows Rust conventions and includes appropriate tests.

Support

If you like this project, consider supporting me on Patreon 💖

Patreon

Changelog

See CHANGELOG.md for a detailed history of changes.


Commit count: 4

cargo fmt