Struct ULID

Source
pub struct ULID { /* private fields */ }
Expand description

A 128-bit Ulid using the ULID layout

  • 0 bits reserved
  • 48 bits timestamp
  • 80 bits random
 Bit Index:  127            80 79           0
             +----------------+-------------+
 Field:      | timestamp (48) | random (80) |
             +----------------+-------------+
             |<-- MSB -- 128 bits -- LSB -->|

Implementations§

Source§

impl ULID

Source

pub const RESERVED_BITS: u128 = 0u128

Source

pub const TIMESTAMP_BITS: u128 = 48u128

Source

pub const RANDOM_BITS: u128 = 80u128

Source

pub const RANDOM_SHIFT: u128 = 0u128

Source

pub const TIMESTAMP_SHIFT: u128 = 80u128

Source

pub const RESERVED_SHIFT: u128 = 128u128

Source

pub const RESERVED_MASK: u128 = 0u128

Source

pub const TIMESTAMP_MASK: u128 = 281_474_976_710_655u128

Source

pub const RANDOM_MASK: u128 = 1_208_925_819_614_629_174_706_175u128

Source

pub const fn from(timestamp: u128, random: u128) -> Self

Source

pub const fn timestamp(&self) -> u128

Extracts the timestamp from the packed ID.

Source

pub const fn random(&self) -> u128

Extracts the random number from the packed ID.

Source

pub const fn max_timestamp() -> u128

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

Source

pub const fn max_random() -> u128

Returns the maximum representable randome value based on Self::RANDOM_BITS.

Source

pub const fn to_raw(&self) -> u128

Converts this type into its raw type representation

Source

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

Converts a raw type into this type

Trait Implementations§

Source§

impl Clone for ULID

Source§

fn clone(&self) -> ULID

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

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ULID

Source§

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

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

impl Display for ULID

Source§

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

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

impl Hash for ULID

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 ULID

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: u128 = 0u128

Zero value (used for resetting the sequence)
Source§

const ONE: u128 = 1u128

One value (used for incrementing the sequence)
Source§

type Ty = u128

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

impl Ord for ULID

Source§

fn cmp(&self, other: &ULID) -> 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 ULID

Source§

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

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

const 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 ULID

Source§

fn partial_cmp(&self, other: &ULID) -> 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 Ulid for ULID

Source§

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

Returns the timestamp portion of the ID.
Source§

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

Returns the random portion of the ID.
Source§

fn max_timestamp() -> Self::Ty

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

fn max_random() -> Self::Ty

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

fn from_components(timestamp: u128, random: u128) -> Self

Constructs a new ULID 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 to_padded_string(&self) -> String

Source§

fn has_random_room(&self) -> bool

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

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

Returns the next sequence value.
Source§

fn increment_random(&self) -> Self

Returns a new ID with the random portion incremented.
Source§

fn rollover_to_timestamp(&self, ts: Self::Ty, rand: Self::Ty) -> Self

Returns a new ID for a newer timestamp with sequence reset to zero.
Source§

impl Copy for ULID

Source§

impl Eq for ULID

Source§

impl StructuralPartialEq for ULID

Auto Trait Implementations§

§

impl Freeze for ULID

§

impl RefUnwindSafe for ULID

§

impl Send for ULID

§

impl Sync for ULID

§

impl Unpin for ULID

§

impl UnwindSafe for ULID

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> Base32Ext for ID
where ID: Id, <ID as Id>::Ty: BeBytes,

Source§

fn encode(&self) -> String

Encodes this ID into a String using Crockford Base32. Read more
Source§

fn encode_to_buf(&self, buf: &mut <<Self as Id>::Ty as BeBytes>::Base32Array)

Encodes this ID into the provided output buffer without heap allocation. Read more
Source§

fn decode(s: &str) -> Result<Self>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more