TimeBasedId Generator
A lightweight Rust library for generating unique identifiers based on system uptime and Unix timestamp. Perfect for applications that need simple, fast, and unique ID generation without external dependencies.
Features
- ๐ Fast generation - No network calls or complex computations
- ๐ข 128-bit identifiers - Ample space for uniqueness
- ๐ฏ Time-based - Combines OS uptime and Unix timestamp
- ๐งช No dependencies - Minimal footprint (except for system uptime)
- ๐ฆ Simple API - Easy to integrate and use
How It Works
The generator creates a 128-bit ID by combining two components:
- OS Uptime (shifted left by 64 bits)
- Current Unix timestamp in nanoseconds
Formula: ID = (uptime << 64) + current_unix_nanoseconds
Usage
Add this to your Cargo.toml:
[]
= "0.1"
Basic usage:
use TimeBasedId;
Ideal Use Cases
This generator is perfect when:
- Objects are created with time intervals greater than 1 nanosecond
- Systems reboot no more than once per second
- You need simple, fast, local ID generation
- You don't require strict chronological ordering across system reboots
Project Structure
src/
โโโ lib.rs # Library exports
โโโ id.rs # Core ID generation logic
API Reference
TimeBasedId
The main struct representing a generated ID.
Methods
-
default() -> Self- Creates a new unique ID -
value(&self) -> u128- Returns the numeric value of the ID
Traits Implemented
DebugCloneEqPartialEqHash
Development
Run test:
Performance
The generator is extremely fast as it only performs:
- One system call for uptime
- One system call for current time
- Two arithmetic operations
License
MIT license in LICENSE file
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.