| Crates.io | idworker |
| lib.rs | idworker |
| version | 0.3.0 |
| created_at | 2025-09-19 04:44:27.682256+00 |
| updated_at | 2025-09-19 06:47:13.738411+00 |
| description | A high-performance distributed ID generator library implementing Snowflake algorithm variants with multiple optimization modes for different performance requirements. |
| homepage | https://github.com/rusthing/idworker |
| repository | https://github.com/rusthing/idworker |
| max_upload_size | |
| id | 1845790 |
| size | 37,773 |
= idworker
A high-performance distributed ID generator library for Rust, implementing Snowflake algorithm variants with multiple optimization modes for different performance requirements.
== Overview
idworker is a Rust library that provides efficient, distributed unique ID generation. It's based on the Snowflake algorithm but includes several optimizations for different performance scenarios. The library is designed for use in distributed systems where globally unique identifiers are needed.
== Features
Normal - Standard performance mode
** Faster - High-performance optimized mode
** Fastest - Maximum performance mode== Installation
Add this to your Cargo.toml:
== Usage
=== Basic Usage
use idworker::generator::IdWorkerGenerator; use idworker::options::{Mode, Options};
fn main() { let options = Options::new() .mode(Mode::Normal) .epoch(1609459200000) // Custom epoch timestamp .data_center(1, 5) // data_center_id, data_center_bits .node(1, 5); // node_id, node_bits
let id_worker = IdWorkerGenerator::generate(options);
let id = id_worker.next_id();
println!("Generated ID: {}", id);
=== Performance Modes
// Normal mode - Standard performance let normal_options = Options::new().mode(Mode::Normal); let normal_worker = IdWorkerGenerator::generate(normal_options);
// Faster mode - High performance let faster_options = Options::new().mode(Mode::Faster); let faster_worker = IdWorkerGenerator::generate(faster_options);
== Performance
The library includes comprehensive benchmarks using Criterion.rs. Run benchmarks with:
== Thread Safety
All ID generators are thread-safe and can be used across multiple threads:
use std::sync::Arc; use std::thread;
let id_worker = Arc::new(IdWorkerGenerator::generate(options)); let mut handles = vec![];
== License
This project is licensed under the MIT License - see the LICENSE file for details.
== Contributing
Contributions are welcome! Please feel free to submit a Pull Request.