1use lazy_static::lazy_static;
2use std::fmt::{Debug, Display};
3use std::sync::Mutex;
4
5#[derive(Hash, Eq, PartialEq, Clone, Copy)]
6pub struct HexoId {
7 batch_id: u64,
8 sequence_id: u64,
9}
10
11impl Display for HexoId {
12 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13 write!(f, "{:x}:{:x}", self.batch_id, self.sequence_id)
14 }
15}
16
17impl Debug for HexoId {
18 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19 write!(f, "{:x}:{:x}", self.batch_id, self.sequence_id)
20 }
21}
22
23lazy_static! {
24 static ref COUNTER: Mutex<u64> = Mutex::new(0);
25}
26
27impl HexoId {
28 pub fn next() -> HexoId {
29 let mut counter = COUNTER.lock().unwrap();
30 *counter += 1;
31 HexoId {
32 sequence_id: *counter,
33 batch_id: 0,
34 }
35 }
36}