pub struct SnowflakeIdGenerator { /* private fields */ }Expand description
A Snowflake ID generator implementation producing 64-bit unique IDs.
Snowflake IDs are composed of:
- A timestamp in milliseconds since a custom epoch (usually a fixed past time),
- A machine ID (or worker ID) to differentiate between nodes,
- A sequence number that increments within the same millisecond to avoid collisions.
Format (64 bits total):
- 41 bits: timestamp (ms since SHORTER_EPOCH)
- 10 bits: machine ID (0-1023)
- 12 bits: sequence number (per ms)
This generator ensures:
- Uniqueness across multiple machines (given unique machine IDs),
- Monotonic increasing IDs when generated in the same process,
- Thread safety with internal locking.
Implementations§
Trait Implementations§
Source§impl<T> IdGenerator<T> for SnowflakeIdGenerator
impl<T> IdGenerator<T> for SnowflakeIdGenerator
Auto Trait Implementations§
impl !Freeze for SnowflakeIdGenerator
impl RefUnwindSafe for SnowflakeIdGenerator
impl Send for SnowflakeIdGenerator
impl Sync for SnowflakeIdGenerator
impl Unpin for SnowflakeIdGenerator
impl UnsafeUnpin for SnowflakeIdGenerator
impl UnwindSafe for SnowflakeIdGenerator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more