atomic_snowflake/snowflake/struct.rs
1use super::*;
2
3/// A 64-bit time-ordered Snowflake identifier (`[0 | 41-bit ts | 10-bit node | 12-bit seq]`).
4#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
5pub struct SnowflakeId {
6 /// Raw 64-bit encoded Snowflake value.
7 pub(crate) raw: u64,
8}
9
10/// Lock-free monotonic 64-bit Snowflake ID generator safe for multi-threaded sharing.
11#[derive(Debug)]
12pub struct SnowflakeGenerator {
13 /// Custom Unix epoch in milliseconds subtracted from wall-clock time.
14 pub(crate) epoch_ms: u64,
15 /// Fixed 10-bit node identifier (`0..=1023`).
16 pub(crate) node_id: u16,
17 /// Packed `(last_relative_ms << 12) | last_sequence` atomic state.
18 pub(crate) state: AtomicU64,
19}