pub struct SnowflakeLongId { /* private fields */ }Expand description
A 128-bit Snowflake ID using a hybrid layout.
- 40 bits reserved
- 48 bits timestamp (ms since
CUSTOM_EPOCH) - 20 bits machine ID
- 20 bits sequence
Bit Index: 127 88 87 40 39 20 19 0
+---------------+----------------+-----------------+---------------+
Field: | reserved (40) | timestamp (48) | machine ID (20) | sequence (20) |
+---------------+----------------+-----------------+---------------+
|<----- HI 64 bits ----->|<-------------- LO 64 bits ------------->|
|<--- MSB ------ LSB --->|<----- MSB ----- 64 bits ----- LSB ----->|Implementations§
Source§impl SnowflakeLongId
impl SnowflakeLongId
pub const RESERVED_BITS: u128 = 40u128
pub const TIMESTAMP_BITS: u128 = 48u128
pub const MACHINE_ID_BITS: u128 = 20u128
pub const SEQUENCE_BITS: u128 = 20u128
pub const SEQUENCE_SHIFT: u128 = 0u128
pub const MACHINE_ID_SHIFT: u128 = 20u128
pub const TIMESTAMP_SHIFT: u128 = 40u128
pub const RESERVED_SHIFT: u128 = 88u128
pub const RESERVED_MASK: u128 = 1_099_511_627_775u128
pub const TIMESTAMP_MASK: u128 = 281_474_976_710_655u128
pub const MACHINE_ID_MASK: u128 = 1_048_575u128
pub const SEQUENCE_MASK: u128 = 1_048_575u128
pub const fn from(timestamp: u128, machine_id: u128, sequence: u128) -> Self
Sourcepub const fn machine_id(&self) -> u128
pub const fn machine_id(&self) -> u128
Extracts the machine ID from the packed ID.
Sourcepub const fn max_timestamp() -> u128
pub const fn max_timestamp() -> u128
Returns the maximum representable timestamp value based on Self::TIMESTAMP_BITS.
Sourcepub const fn max_machine_id() -> u128
pub const fn max_machine_id() -> u128
Returns the maximum representable machine ID value based on Self::MACHINE_ID_BITS.
Sourcepub const fn max_sequence() -> u128
pub const fn max_sequence() -> u128
Returns the maximum representable sequence value based on Self::SEQUENCE_BITS.
Trait Implementations§
Source§impl Clone for SnowflakeLongId
impl Clone for SnowflakeLongId
Source§fn clone(&self) -> SnowflakeLongId
fn clone(&self) -> SnowflakeLongId
Returns a duplicate of the value. Read more
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SnowflakeLongId
impl Debug for SnowflakeLongId
Source§impl Display for SnowflakeLongId
impl Display for SnowflakeLongId
Source§impl Hash for SnowflakeLongId
impl Hash for SnowflakeLongId
Source§impl Id for SnowflakeLongId
impl Id for SnowflakeLongId
Source§impl Ord for SnowflakeLongId
impl Ord for SnowflakeLongId
Source§fn cmp(&self, other: &SnowflakeLongId) -> Ordering
fn cmp(&self, other: &SnowflakeLongId) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for SnowflakeLongId
impl PartialEq for SnowflakeLongId
Source§impl PartialOrd for SnowflakeLongId
impl PartialOrd for SnowflakeLongId
Source§impl Snowflake for SnowflakeLongId
impl Snowflake for SnowflakeLongId
Source§fn machine_id(&self) -> Self::Ty
fn machine_id(&self) -> Self::Ty
Returns the machine ID portion of the ID.
Source§fn max_timestamp() -> Self::Ty
fn max_timestamp() -> Self::Ty
Returns the maximum possible value for the timestamp field.
Source§fn max_machine_id() -> Self::Ty
fn max_machine_id() -> Self::Ty
Returns the maximum possible value for the machine_id field.
Source§fn max_sequence() -> Self::Ty
fn max_sequence() -> Self::Ty
Returns the maximum possible value for the sequence field.
Source§fn from_components(timestamp: u128, machine_id: u128, sequence: u128) -> Self
fn from_components(timestamp: u128, machine_id: u128, sequence: u128) -> Self
Constructs a new Snowflake ID from its components.
Source§fn is_valid(&self) -> bool
fn is_valid(&self) -> bool
Returns
true if the ID’s internal structure is valid, such as reserved
bits being unset or fields within expected ranges.Source§fn into_valid(self) -> Self
fn into_valid(self) -> Self
Returns a normalized version of the ID with any invalid or reserved bits
cleared. This guarantees a valid, canonical representation.
fn to_padded_string(&self) -> String
Source§fn has_sequence_room(&self) -> bool
fn has_sequence_room(&self) -> bool
Returns true if the current sequence value can be incremented.
Source§fn next_sequence(&self) -> Self::Ty
fn next_sequence(&self) -> Self::Ty
Returns the next sequence value.
Source§fn increment_sequence(&self) -> Self
fn increment_sequence(&self) -> Self
Returns a new ID with the sequence incremented.
Source§fn rollover_to_timestamp(&self, ts: Self::Ty) -> Self
fn rollover_to_timestamp(&self, ts: Self::Ty) -> Self
Returns a new ID for a newer timestamp with sequence reset to zero.
impl Copy for SnowflakeLongId
impl Eq for SnowflakeLongId
impl StructuralPartialEq for SnowflakeLongId
Auto Trait Implementations§
impl Freeze for SnowflakeLongId
impl RefUnwindSafe for SnowflakeLongId
impl Send for SnowflakeLongId
impl Sync for SnowflakeLongId
impl Unpin for SnowflakeLongId
impl UnwindSafe for SnowflakeLongId
Blanket Implementations§
Source§impl<ID> Base32Ext for ID
impl<ID> Base32Ext for ID
Source§fn encode_to_buf(&self, buf: &mut <<Self as Id>::Ty as BeBytes>::Base32Array)
fn encode_to_buf(&self, buf: &mut <<Self as Id>::Ty as BeBytes>::Base32Array)
Encodes this ID into the provided output buffer without heap allocation. Read more
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