| Crates.io | timebased-id |
| lib.rs | timebased-id |
| version | 0.1.0 |
| created_at | 2025-12-03 09:17:41.075704+00 |
| updated_at | 2025-12-03 09:17:41.075704+00 |
| description | 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. |
| homepage | https://github.com/greyshaman/timebased-id |
| repository | https://github.com/greyshaman/timebased-id |
| max_upload_size | |
| id | 1963670 |
| size | 7,597 |
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.
The generator creates a 128-bit ID by combining two components:
Formula: ID = (uptime << 64) + current_unix_nanoseconds
Add this to your Cargo.toml:
[dependencies]
timebased-id = "0.1"
Basic usage:
use timebased_id::TimeBasedId;
fn main() {
// Generate new Id:
let id = TimeBasedId::default();
// Get the numeric id
let value = id.value();
println!("Generated id: {}", value);
// IDs are unique (for non-simultaneous generation )
let id2 = TimeBasedId::default();
assert_ne!(id.value(), id2.value());
}
This generator is perfect when:
src/
โโโ lib.rs # Library exports
โโโ id.rs # Core ID generation logic
TimeBasedId
The main struct representing a generated ID.
default() -> Self - Creates a new unique ID
value(&self) -> u128 - Returns the numeric value of the ID
DebugCloneEqPartialEqHashRun test:
cargo test
The generator is extremely fast as it only performs:
MIT license in LICENSE file
Contributions are welcome! Please feel free to submit a Pull Request.