pub struct SnowflakeDiscordId { /* private fields */ }Expand description
A 64-bit Snowflake ID using the Discord layout
- 42 bits timestamp (ms since
DISCORD_EPOCH) - 10 bits machine ID (worker ID (5) and process ID (5))
- 12 bits sequence
Bit Index: 63 22 21 12 11 0
+----------------+-----------------+---------------+
Field: | timestamp (42) | machine ID (10) | sequence (12) |
+----------------+-----------------+---------------+
|<----- MSB ---------- 64 bits --------- LSB ----->|Implementations§
Source§impl SnowflakeDiscordId
impl SnowflakeDiscordId
pub const RESERVED_BITS: u64 = 0u64
pub const TIMESTAMP_BITS: u64 = 42u64
pub const MACHINE_ID_BITS: u64 = 10u64
pub const SEQUENCE_BITS: u64 = 12u64
pub const SEQUENCE_SHIFT: u64 = 0u64
pub const MACHINE_ID_SHIFT: u64 = 12u64
pub const TIMESTAMP_SHIFT: u64 = 22u64
pub const RESERVED_SHIFT: u64 = 64u64
pub const RESERVED_MASK: u64 = 0u64
pub const TIMESTAMP_MASK: u64 = 4_398_046_511_103u64
pub const MACHINE_ID_MASK: u64 = 1_023u64
pub const SEQUENCE_MASK: u64 = 4_095u64
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.
Trait Implementations§
Source§impl Clone for SnowflakeDiscordId
impl Clone for SnowflakeDiscordId
Source§fn clone(&self) -> SnowflakeDiscordId
fn clone(&self) -> SnowflakeDiscordId
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SnowflakeDiscordId
impl Debug for SnowflakeDiscordId
Source§impl Display for SnowflakeDiscordId
impl Display for SnowflakeDiscordId
Source§impl Hash for SnowflakeDiscordId
impl Hash for SnowflakeDiscordId
Source§impl Ord for SnowflakeDiscordId
impl Ord for SnowflakeDiscordId
Source§fn cmp(&self, other: &SnowflakeDiscordId) -> Ordering
fn cmp(&self, other: &SnowflakeDiscordId) -> 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 SnowflakeDiscordId
impl PartialEq for SnowflakeDiscordId
Source§impl PartialOrd for SnowflakeDiscordId
impl PartialOrd for SnowflakeDiscordId
Source§impl Snowflake for SnowflakeDiscordId
impl Snowflake for SnowflakeDiscordId
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: u64, machine_id: u64, sequence: u64) -> Self
fn from_components(timestamp: u64, machine_id: u64, sequence: u64) -> Self
Constructs a new Snowflake ID from its components.
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 SnowflakeDiscordId
impl Eq for SnowflakeDiscordId
impl StructuralPartialEq for SnowflakeDiscordId
Auto Trait Implementations§
impl Freeze for SnowflakeDiscordId
impl RefUnwindSafe for SnowflakeDiscordId
impl Send for SnowflakeDiscordId
impl Sync for SnowflakeDiscordId
impl Unpin for SnowflakeDiscordId
impl UnwindSafe for SnowflakeDiscordId
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