pub struct SnowflakeMastodonId { /* private fields */ }Expand description
A 64-bit Snowflake ID using the Mastodon layout
- 48 bits timestamp (ms since
MASTODON_EPOCH) - 16 bits sequence
Bit Index: 63 16 15 0
+----------------+---------------+
Field: | timestamp (48) | sequence (16) |
+----------------+---------------+
|<--- MSB --- 64 bits -- LSB --->|Implementations§
Source§impl SnowflakeMastodonId
impl SnowflakeMastodonId
pub const RESERVED_BITS: u64 = 0u64
pub const TIMESTAMP_BITS: u64 = 48u64
pub const MACHINE_ID_BITS: u64 = 0u64
pub const SEQUENCE_BITS: u64 = 16u64
pub const SEQUENCE_SHIFT: u64 = 0u64
pub const MACHINE_ID_SHIFT: u64 = 16u64
pub const TIMESTAMP_SHIFT: u64 = 16u64
pub const RESERVED_SHIFT: u64 = 64u64
pub const RESERVED_MASK: u64 = 0u64
pub const TIMESTAMP_MASK: u64 = 281_474_976_710_655u64
pub const MACHINE_ID_MASK: u64 = 0u64
pub const SEQUENCE_MASK: u64 = 65_535u64
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 const fn max_timestamp() -> u64
pub const fn max_timestamp() -> u64
Returns the maximum representable timestamp value based on
Self::TIMESTAMP_BITS.
Sourcepub const fn max_machine_id() -> u64
pub const fn max_machine_id() -> u64
Returns the maximum representable machine ID value based on
Self::MACHINE_ID_BITS.
Sourcepub const fn max_sequence() -> u64
pub const fn max_sequence() -> u64
Returns the maximum representable sequence value based on
Self::SEQUENCE_BITS.
Trait Implementations§
Source§impl Clone for SnowflakeMastodonId
impl Clone for SnowflakeMastodonId
Source§fn clone(&self) -> SnowflakeMastodonId
fn clone(&self) -> SnowflakeMastodonId
Returns a duplicate 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 Display for SnowflakeMastodonId
impl Display for SnowflakeMastodonId
Source§impl FromStr for SnowflakeMastodonId
impl FromStr for SnowflakeMastodonId
Source§impl Hash for SnowflakeMastodonId
impl Hash for SnowflakeMastodonId
Source§impl Id for SnowflakeMastodonId
impl Id 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 SnowflakeId for SnowflakeMastodonId
impl SnowflakeId for SnowflakeMastodonId
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.
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.
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.
Source§impl TryFrom<&str> for SnowflakeMastodonId
impl TryFrom<&str> for SnowflakeMastodonId
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<ID> Base32SnowExt for ID
impl<ID> Base32SnowExt for ID
Source§fn buf() -> <<Self as Id>::Ty as BeBytes>::Base32Array
fn buf() -> <<Self as Id>::Ty as BeBytes>::Base32Array
Returns a stack-allocated, zero-initialized buffer for Base32 encoding. Read more
Source§fn encode(&self) -> Base32SnowFormatter<Self>
fn encode(&self) -> Base32SnowFormatter<Self>
Returns a formatter containing the Crockford Base32 representation of
the ID. Read more
Source§fn encode_to_buf<'buf>(
&self,
buf: &'buf mut <<Self as Id>::Ty as BeBytes>::Base32Array,
) -> Base32SnowFormatterRef<'buf, Self>
fn encode_to_buf<'buf>( &self, buf: &'buf mut <<Self as Id>::Ty as BeBytes>::Base32Array, ) -> Base32SnowFormatterRef<'buf, Self>
Encodes this ID into the provided buffer without heap allocation and
returns a formatter view over the buffer similar to
Base32SnowExt::encode. Read moreSource§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