Skip to main content

atomic_snowflake/ulid/
struct.rs

1use super::*;
2
3/// A 128-bit lexicographically sortable ULID (`48-bit ms timestamp | 80-bit entropy`).
4#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
5pub struct Ulid {
6    /// Raw big-endian 128-bit ULID integer.
7    pub(crate) raw: u128,
8}
9
10/// Lock-free monotonic 128-bit ULID generator using atomic state and SplitMix64 entropy.
11#[derive(Debug)]
12pub struct UlidGenerator {
13    /// Packed `(last_ms_48 << 16) | last_rand_hi_16` atomic word.
14    pub(crate) hi_state: AtomicU64,
15    /// Low 64 bits of the monotonic random suffix.
16    pub(crate) lo_state: AtomicU64,
17    /// Rolling SplitMix64 entropy seed.
18    pub(crate) seed: AtomicU64,
19}