2 stable releases
1.0.1 | Jan 15, 2024 |
---|---|
1.0.0 | Sep 21, 2023 |
#1018 in Data structures
7KB
59 lines
Chronoflake
Crate to generate unique 64-bit IDs in centralised or decentralised systems.
Based on the Twitter Snowflake algorithm.
Usage
use chronoflake::IdGenerator;
const MACHINE_ID: u16 = 49;
fn main() {
// Create an ID generator using the default (Twitter) epoch
let mut cf = IdGenerator::new(MACHINE_ID);
// Generate a unique ID
let id = cf.generate_id();
// Futher processing...
}
lib.rs
:
Generate unique IDs for a variety of purposes.
Based on the Twitter Snowflake algorithm for generating unique IDs for messages
Usage
use chronoflake::IdGenerator;
const PROJECT_EPOCH: u64 = 1488432924251;
fn main() {
let mut cf = IdGenerator::new(14)
.with_epoch(PROJECT_EPOCH);
let id = cf.generate_id();
println!("ID: {id}"); // 1704967240656416804
}
Dependencies
~1MB
~18K SLoC