pub struct SnowflakeDiscordId { /* private fields */ }Expand description
A 64-bit Snowflake ID using the Discord layout
NOTE: To keep the API the same, we’re collapsing their notation of machine and process id into the same number of bits.
- 42 bits timestamp (ms since Discord epoch: Jan 1, 2015 UTC)
- 10 bits internal worker ID (5) and process ID (5), combined into machine_id (10)
- 12 bits increment
| timestamp (42) | machine_id (10) | sequence (12) |Implementations§
Source§impl SnowflakeDiscordId
impl SnowflakeDiscordId
Sourcepub const TIMESTAMP_MASK: u64 = 4_398_046_511_103u64
pub const TIMESTAMP_MASK: u64 = 4_398_046_511_103u64
Bitmask for extracting the 42-bit timestamp field from a packed ID. Occupies bits 22 through 63 (most significant bits).
Sourcepub const MACHINE_ID_MASK: u64 = 1_023u64
pub const MACHINE_ID_MASK: u64 = 1_023u64
Bitmask for extracting the 10-bit machine ID field. Occupies bits 12 through 21.
Sourcepub const SEQUENCE_MASK: u64 = 4_095u64
pub const SEQUENCE_MASK: u64 = 4_095u64
Bitmask for extracting the 12-bit sequence field. Occupies bits 0 through 11.
Sourcepub const TIMESTAMP_SHIFT: u64 = 22u64
pub const TIMESTAMP_SHIFT: u64 = 22u64
Number of bits to shift the timestamp to its correct position (starting at bit 22).
Sourcepub const MACHINE_ID_SHIFT: u64 = 12u64
pub const MACHINE_ID_SHIFT: u64 = 12u64
Number of bits to shift the process/machine ID to its correct position.
Sourcepub const SEQUENCE_SHIFT: u64 = 0u64
pub const SEQUENCE_SHIFT: u64 = 0u64
Number of bits to shift the sequence field (starts at the least significant bit).
pub const fn from(timestamp: u64, machine_id: u64, sequence: u64) -> Self
Sourcepub const fn machine_id(&self) -> u64
pub const fn machine_id(&self) -> u64
Extracts the machine ID from the packed ID.
Sourcepub fn to_padded_string(&self) -> String
pub fn to_padded_string(&self) -> String
Returns the ID as a zero-padded 20-digit string.
Trait Implementations§
Source§impl Base32 for SnowflakeDiscordId
impl Base32 for SnowflakeDiscordId
Source§impl Clone for SnowflakeDiscordId
impl Clone for SnowflakeDiscordId
Source§fn clone(&self) -> SnowflakeDiscordId
fn clone(&self) -> SnowflakeDiscordId
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more