pub struct SnowflakeMastodonId { /* private fields */ }Expand description
A 64-bit Snowflake ID using the Mastodon layout
- 48 bits timestamp (ms since UNIX epoch)
- 16 bits sequence
| timestamp (48) | sequence (16) |Implementations§
Source§impl SnowflakeMastodonId
impl SnowflakeMastodonId
Sourcepub const TIMESTAMP_MASK: u64 = 281_474_976_710_655u64
pub const TIMESTAMP_MASK: u64 = 281_474_976_710_655u64
Mask for 48-bit timestamp field (used to extract the upper 48 bits). This corresponds to millisecond precision since the UNIX epoch.
Sourcepub const SEQUENCE_MASK: u64 = 65_535u64
pub const SEQUENCE_MASK: u64 = 65_535u64
Mask for 16-bit sequence field (used to extract the lower 16 bits). This provides up to 65,536 unique IDs per millisecond.
Sourcepub const TIMESTAMP_SHIFT: u64 = 16u64
pub const TIMESTAMP_SHIFT: u64 = 16u64
Bit offset for timestamp (starts at bit 16, leaving room for 16-bit sequence).
Sourcepub const SEQUENCE_SHIFT: u64 = 0u64
pub const SEQUENCE_SHIFT: u64 = 0u64
Bit offset for sequence (least significant 16 bits).
pub const fn from(timestamp: u64, sequence: u64) -> Self
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 SnowflakeMastodonId
impl Base32 for SnowflakeMastodonId
Source§impl Clone for SnowflakeMastodonId
impl Clone for SnowflakeMastodonId
Source§fn clone(&self) -> SnowflakeMastodonId
fn clone(&self) -> SnowflakeMastodonId
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 SnowflakeMastodonId
impl Debug for SnowflakeMastodonId
Source§impl<'de> Deserialize<'de> for SnowflakeMastodonId
impl<'de> Deserialize<'de> for SnowflakeMastodonId
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 SnowflakeMastodonId
impl Display for SnowflakeMastodonId
Source§impl Hash for SnowflakeMastodonId
impl Hash for SnowflakeMastodonId
Source§impl Ord for SnowflakeMastodonId
impl Ord for SnowflakeMastodonId
Source§fn cmp(&self, other: &SnowflakeMastodonId) -> Ordering
fn cmp(&self, other: &SnowflakeMastodonId) -> 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 SnowflakeMastodonId
impl PartialEq for SnowflakeMastodonId
Source§impl PartialOrd for SnowflakeMastodonId
impl PartialOrd for SnowflakeMastodonId
Source§impl Serialize for SnowflakeMastodonId
impl Serialize for SnowflakeMastodonId
Source§impl Snowflake for SnowflakeMastodonId
impl Snowflake for SnowflakeMastodonId
Source§const ZERO: Self::Ty = {transmute(0x0000000000000000): <id::SnowflakeMastodonId as id::Snowflake>::Ty}
const ZERO: Self::Ty = {transmute(0x0000000000000000): <id::SnowflakeMastodonId as id::Snowflake>::Ty}
Zero value (used for resetting the sequence)
Source§const ONE: Self::Ty = {transmute(0x0000000000000001): <id::SnowflakeMastodonId as id::Snowflake>::Ty}
const ONE: Self::Ty = {transmute(0x0000000000000001): <id::SnowflakeMastodonId 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.
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 SnowflakeMastodonId
impl Eq for SnowflakeMastodonId
impl StructuralPartialEq for SnowflakeMastodonId
Auto Trait Implementations§
impl Freeze for SnowflakeMastodonId
impl RefUnwindSafe for SnowflakeMastodonId
impl Send for SnowflakeMastodonId
impl Sync for SnowflakeMastodonId
impl Unpin for SnowflakeMastodonId
impl UnwindSafe for SnowflakeMastodonId
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