pub struct SnowflakeId { /* private fields */ }Expand description
A 64-bit time-ordered Snowflake identifier ([0 | 41-bit ts | 10-bit node | 12-bit seq]).
Implementations§
Source§impl SnowflakeId
Accessors and codecs for SnowflakeId.
impl SnowflakeId
Accessors and codecs for SnowflakeId.
Sourcepub const fn from_u64(raw: u64) -> Self
pub const fn from_u64(raw: u64) -> Self
Wraps a raw 64-bit integer as a SnowflakeId.
§Arguments
u64- The raw 64-bit Snowflake integer.
§Returns
Self- The typed Snowflake ID wrapper.
Sourcepub const fn from_parts(relative_ms: u64, node_id: u16, sequence: u16) -> Self
pub const fn from_parts(relative_ms: u64, node_id: u16, sequence: u16) -> Self
Composes a SnowflakeId directly from its fields.
§Arguments
u64- Milliseconds elapsed since the generator’s custom epoch (masked to 41 bits).u16- 10-bit node identifier (0..=1023).u16- 12-bit sequence counter (0..=4095).
§Returns
Self- The composed Snowflake identifier.
Sourcepub const fn timestamp_offset_ms(self) -> u64
pub const fn timestamp_offset_ms(self) -> u64
Returns the 41-bit timestamp offset in milliseconds relative to the custom epoch.
§Returns
u64- Elapsed milliseconds since custom epoch.
Sourcepub const fn timestamp_ms(self, epoch_ms: u64) -> u64
pub const fn timestamp_ms(self, epoch_ms: u64) -> u64
Sourcepub const fn node_id(self) -> u16
pub const fn node_id(self) -> u16
Returns the 10-bit node identifier embedded in the Snowflake ID.
§Returns
u16- Node identifier in0..=1023.
Sourcepub const fn sequence(self) -> u16
pub const fn sequence(self) -> u16
Returns the 12-bit sequence counter embedded in the Snowflake ID.
§Returns
u16- Sequence number in0..=4095.
Sourcepub fn to_base62(self) -> String
pub fn to_base62(self) -> String
Encodes the Snowflake ID into a compact Base62 string.
§Returns
String- Base62 textual encoding (1 to 11 ASCII characters).
Sourcepub fn from_base62(input: &str) -> Result<Self, IdError>
pub fn from_base62(input: &str) -> Result<Self, IdError>
Decodes a Base62 string back into a SnowflakeId.
§Arguments
&str- The Base62 encoded string.
§Returns
Result<Self, IdError>- The decoded Snowflake ID or parse error.
Trait Implementations§
Source§impl Clone for SnowflakeId
impl Clone for SnowflakeId
impl Copy for SnowflakeId
Source§impl Debug for SnowflakeId
impl Debug for SnowflakeId
Source§impl Default for SnowflakeId
impl Default for SnowflakeId
Source§impl Display for SnowflakeId
Formats SnowflakeId as a base-10 integer string.
impl Display for SnowflakeId
Formats SnowflakeId as a base-10 integer string.
impl Eq for SnowflakeId
Source§impl From<SnowflakeId> for u64
Converts SnowflakeId into u64.
impl From<SnowflakeId> for u64
Converts SnowflakeId into u64.
Source§impl From<u64> for SnowflakeId
Converts u64 into SnowflakeId.
impl From<u64> for SnowflakeId
Converts u64 into SnowflakeId.
Source§impl FromStr for SnowflakeId
Parses a base-10 string into a SnowflakeId.
impl FromStr for SnowflakeId
Parses a base-10 string into a SnowflakeId.
Source§impl Hash for SnowflakeId
impl Hash for SnowflakeId
Source§impl Ord for SnowflakeId
impl Ord for SnowflakeId
1.21.0 (const: unstable) · 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
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialEq for SnowflakeId
impl PartialEq for SnowflakeId
Source§impl PartialOrd for SnowflakeId
impl PartialOrd for SnowflakeId
impl StructuralPartialEq for SnowflakeId
Auto Trait Implementations§
impl Forget for SnowflakeId
impl Freeze for SnowflakeId
impl Move for SnowflakeId
impl RefUnwindSafe for SnowflakeId
impl Send for SnowflakeId
impl Sync for SnowflakeId
impl Unpin for SnowflakeId
impl UnsafeUnpin for SnowflakeId
impl UnwindSafe for SnowflakeId
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