pub struct SnowflakeInstagramId { /* private fields */ }Expand description
A 64-bit Snowflake ID using the Instagram layout
- 41 bits timestamp (ms since UNIX epoch)
- 13 bits machine ID
- 10 bits sequence
| timestamp (48) | machine(13) | sequence (10) |Implementations§
Source§impl SnowflakeInstagramId
impl SnowflakeInstagramId
Sourcepub const TIMESTAMP_MASK: u64 = 2_199_023_255_551u64
pub const TIMESTAMP_MASK: u64 = 2_199_023_255_551u64
Mask for 41-bit timestamp field (milliseconds since a custom epoch). Ensures timestamps stay within the expected range and fit in the upper bits.
Sourcepub const MACHINE_ID_MASK: u64 = 8_191u64
pub const MACHINE_ID_MASK: u64 = 8_191u64
Mask for 13-bit machine ID field (shard or datacenter). Supports up to 8192 unique machine IDs.
Sourcepub const SEQUENCE_MASK: u64 = 1_023u64
pub const SEQUENCE_MASK: u64 = 1_023u64
Mask for 10-bit sequence field. Allows up to 1024 unique IDs to be generated per millisecond per machine.
Sourcepub const TIMESTAMP_SHIFT: u64 = 23u64
pub const TIMESTAMP_SHIFT: u64 = 23u64
Bit offset for timestamp (starts at bit 23).
Sourcepub const MACHINE_ID_SHIFT: u64 = 10u64
pub const MACHINE_ID_SHIFT: u64 = 10u64
Bit offset for machine ID (starts at bit 10).
Sourcepub const SEQUENCE_SHIFT: u64 = 0u64
pub const SEQUENCE_SHIFT: u64 = 0u64
Bit offset for sequence (least significant 10 bits).
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 SnowflakeInstagramId
impl Base32 for SnowflakeInstagramId
Source§impl Clone for SnowflakeInstagramId
impl Clone for SnowflakeInstagramId
Source§fn clone(&self) -> SnowflakeInstagramId
fn clone(&self) -> SnowflakeInstagramId
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 SnowflakeInstagramId
impl Debug for SnowflakeInstagramId
Source§impl<'de> Deserialize<'de> for SnowflakeInstagramId
impl<'de> Deserialize<'de> for SnowflakeInstagramId
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for SnowflakeInstagramId
impl Display for SnowflakeInstagramId
Source§impl Hash for SnowflakeInstagramId
impl Hash for SnowflakeInstagramId
Source§impl Ord for SnowflakeInstagramId
impl Ord for SnowflakeInstagramId
Source§fn cmp(&self, other: &SnowflakeInstagramId) -> Ordering
fn cmp(&self, other: &SnowflakeInstagramId) -> 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 SnowflakeInstagramId
impl PartialEq for SnowflakeInstagramId
Source§impl PartialOrd for SnowflakeInstagramId
impl PartialOrd for SnowflakeInstagramId
Source§impl Serialize for SnowflakeInstagramId
impl Serialize for SnowflakeInstagramId
Source§impl Snowflake for SnowflakeInstagramId
impl Snowflake for SnowflakeInstagramId
Source§const ZERO: Self::Ty = {transmute(0x0000000000000000): <id::SnowflakeInstagramId as id::Snowflake>::Ty}
const ZERO: Self::Ty = {transmute(0x0000000000000000): <id::SnowflakeInstagramId as id::Snowflake>::Ty}
Zero value (used for resetting the sequence)
Source§const ONE: Self::Ty = {transmute(0x0000000000000001): <id::SnowflakeInstagramId as id::Snowflake>::Ty}
const ONE: Self::Ty = {transmute(0x0000000000000001): <id::SnowflakeInstagramId as id::Snowflake>::Ty}
One value (used for incrementing the sequence)
Source§fn max_timestamp() -> Self::Ty
fn max_timestamp() -> Self::Ty
Returns the maximum possible value for the timestamp field.
Source§fn machine_id(&self) -> Self::Ty
fn machine_id(&self) -> Self::Ty
Returns the machine ID portion of the ID.
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: Self::Ty,
machine_id: Self::Ty,
sequence: Self::Ty,
) -> Self
fn from_components( timestamp: Self::Ty, machine_id: Self::Ty, sequence: Self::Ty, ) -> Self
Constructs a new Snowflake ID from its components.
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.
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.
impl Copy for SnowflakeInstagramId
impl Eq for SnowflakeInstagramId
impl StructuralPartialEq for SnowflakeInstagramId
Auto Trait Implementations§
impl Freeze for SnowflakeInstagramId
impl RefUnwindSafe for SnowflakeInstagramId
impl Send for SnowflakeInstagramId
impl Sync for SnowflakeInstagramId
impl Unpin for SnowflakeInstagramId
impl UnwindSafe for SnowflakeInstagramId
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