SnowflakeInstagramId

Struct SnowflakeInstagramId 

Source
pub struct SnowflakeInstagramId { /* private fields */ }
Available on crate feature snowflake only.
Expand description

A 64-bit Snowflake ID using the Instagram layout

  • 41 bits timestamp (ms since INSTAGRAM_EPOCH)
  • 13 bits machine ID
  • 10 bits sequence
 Bit Index:  63             23 22             10 9              0
             +----------------+-----------------+---------------+
 Field:      | timestamp (41) | machine ID (13) | sequence (10) |
             +----------------+-----------------+---------------+
             |<----- MSB ---------- 64 bits --------- LSB ----->|

Implementations§

Source§

impl SnowflakeInstagramId

Source

pub const RESERVED_BITS: u64 = 0u64

Source

pub const TIMESTAMP_BITS: u64 = 41u64

Source

pub const MACHINE_ID_BITS: u64 = 13u64

Source

pub const SEQUENCE_BITS: u64 = 10u64

Source

pub const SEQUENCE_SHIFT: u64 = 0u64

Source

pub const MACHINE_ID_SHIFT: u64 = 10u64

Source

pub const TIMESTAMP_SHIFT: u64 = 23u64

Source

pub const RESERVED_SHIFT: u64 = 64u64

Source

pub const RESERVED_MASK: u64 = 0u64

Source

pub const TIMESTAMP_MASK: u64 = 2_199_023_255_551u64

Source

pub const MACHINE_ID_MASK: u64 = 8_191u64

Source

pub const SEQUENCE_MASK: u64 = 1_023u64

Source

pub const fn from(timestamp: u64, machine_id: u64, sequence: u64) -> Self

Source

pub const fn timestamp(&self) -> u64

Extracts the timestamp from the packed ID.

Source

pub const fn machine_id(&self) -> u64

Extracts the machine ID from the packed ID.

Source

pub const fn sequence(&self) -> u64

Extracts the sequence number from the packed ID.

Source

pub const fn max_timestamp() -> u64

Returns the maximum representable timestamp value based on Self::TIMESTAMP_BITS.

Source

pub const fn max_machine_id() -> u64

Returns the maximum representable machine ID value based on Self::MACHINE_ID_BITS.

Source

pub const fn max_sequence() -> u64

Returns the maximum representable sequence value based on Self::SEQUENCE_BITS.

Source

pub const fn to_raw(&self) -> u64

Converts this type into its raw type representation

Source

pub const fn from_raw(raw: u64) -> Self

Converts a raw type into this type

Trait Implementations§

Source§

impl Clone for SnowflakeInstagramId

Source§

fn clone(&self) -> SnowflakeInstagramId

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SnowflakeInstagramId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for SnowflakeInstagramId

Available on crate feature base32 only.
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for SnowflakeInstagramId

Available on crate feature base32 only.
Source§

type Err = Error<SnowflakeInstagramId>

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for SnowflakeInstagramId

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Id for SnowflakeInstagramId

Source§

fn to_raw(&self) -> Self::Ty

Converts this type into its raw type representation

Source§

fn from_raw(raw: Self::Ty) -> Self

Converts a raw type into this type

Source§

const ZERO: u64 = 0u64

Zero value (used for resetting the sequence)
Source§

const ONE: u64 = 1u64

One value (used for incrementing the sequence)
Source§

type Ty = u64

Scalar type for all bit fields (typically u64 or u128)
Source§

impl Ord for SnowflakeInstagramId

Source§

fn cmp(&self, other: &SnowflakeInstagramId) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for SnowflakeInstagramId

Source§

fn eq(&self, other: &SnowflakeInstagramId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for SnowflakeInstagramId

Source§

fn partial_cmp(&self, other: &SnowflakeInstagramId) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl SnowflakeId for SnowflakeInstagramId

Source§

fn timestamp(&self) -> Self::Ty

Returns the timestamp portion of the ID.
Source§

fn machine_id(&self) -> Self::Ty

Returns the machine ID portion of the ID.
Source§

fn sequence(&self) -> Self::Ty

Returns the sequence portion of the ID.
Source§

fn max_timestamp() -> Self::Ty

Returns the maximum possible value for the timestamp field.
Source§

fn max_machine_id() -> Self::Ty

Returns the maximum possible value for the machine_id field.
Source§

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

Constructs a new Snowflake ID from its components.
Source§

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

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

Returns true if the current sequence value can be incremented.
Source§

fn next_sequence(&self) -> Self::Ty

Returns the next sequence value.
Source§

fn increment_sequence(&self) -> Self

Returns a new ID with the sequence incremented.
Source§

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 SnowflakeInstagramId

Available on crate feature base32 only.
Source§

type Error = Error<SnowflakeInstagramId>

The type returned in the event of a conversion error.
Source§

fn try_from(s: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy for SnowflakeInstagramId

Source§

impl Eq for SnowflakeInstagramId

Source§

impl StructuralPartialEq for SnowflakeInstagramId

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<ID> Base32SnowExt for ID
where ID: SnowflakeId, <ID as Id>::Ty: BeBytes,

Source§

fn buf() -> <<Self as Id>::Ty as BeBytes>::Base32Array

Available on crate features base32 and snowflake only.
Returns a stack-allocated, zero-initialized buffer for Base32 encoding. Read more
Source§

fn encode(&self) -> Base32SnowFormatter<Self>

Available on crate features base32 and snowflake only.
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>

Available on crate features base32 and snowflake only.
Encodes this ID into the provided buffer without heap allocation and returns a formatter view over the buffer similar to Base32SnowExt::encode. Read more
Source§

fn decode(s: impl AsRef<str>) -> Result<Self, Error<Self>>

Available on crate features base32 and snowflake only.
Decodes a Base32-encoded string back into an ID. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V