Crate hora_id

Crate hora_id 

Source
Expand description

Time sorted unique ID generator IDs are time-sorted and 8 bytes long, which is half the length of a UUID and ULID

§Composition

HoraID has 3 parts

  • 4 byte timestamp high
  • 1 byte timestamp low
  • 1 byte for machine ID (0-255)
  • 2 bytes for sequence number

§Usage

Generate IDs in a distributed system

use hora_id::{HoraGenerator, HoraId};

let machine_id = 1; // You'll ideally get this from environment variable or configuration
 let mut generator: HoraGenerator = HoraGenerator::new(machine_id).unwrap();

let id: HoraId = generator.next();
println!("{}", id.to_string()); // example: '00cd01daff010002'
println!("{}", id.to_u64()); // example: 57704355272392706
println!("{}", id.to_datetime()); // example: 2025-03-20 00:00:00
println!("{}", id.to_utc()); // example: 2025-03-20 00:00:00 UTC

Quickly generate a new ID.

use hora_id::HoraId;
let id = HoraId::rand().unwrap();

Structs§

HoraGenerator
ID Generator with guarantee to generate time-based unique IDs on a single machine
HoraId
A time-sorted 8-byte (64-bit) unique identifier