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
impl ULID
pub const RESERVED_BITS: u128 = 0u128
pub const TIMESTAMP_BITS: u128 = 48u128
pub const RANDOM_BITS: u128 = 80u128
pub const RANDOM_SHIFT: u128 = 0u128
pub const TIMESTAMP_SHIFT: u128 = 80u128
pub const RESERVED_SHIFT: u128 = 128u128
pub const RESERVED_MASK: u128 = 0u128
pub const TIMESTAMP_MASK: u128 = 281_474_976_710_655u128
pub const RANDOM_MASK: u128 = 1_208_925_819_614_629_174_706_175u128
pub const fn from(timestamp: u128, random: u128) -> Self
Sourcepub const fn max_timestamp() -> u128
pub const fn max_timestamp() -> u128
Returns the maximum representable timestamp value based on Self::TIMESTAMP_BITS.
Sourcepub const fn max_random() -> u128
pub const fn max_random() -> u128
Returns the maximum representable randome value based on Self::RANDOM_BITS.
Trait Implementations§
Source§impl Ord for ULID
impl Ord for ULID
Source§impl PartialOrd for ULID
impl PartialOrd for ULID
Source§impl Ulid for ULID
impl Ulid for ULID
Source§fn max_timestamp() -> Self::Ty
fn max_timestamp() -> Self::Ty
Returns the maximum possible value for the timestamp field.
Source§fn max_random() -> Self::Ty
fn max_random() -> Self::Ty
Returns the maximum possible value for the random field.
Source§fn from_components(timestamp: u128, random: u128) -> Self
fn from_components(timestamp: u128, random: u128) -> Self
Constructs a new ULID 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.
fn to_padded_string(&self) -> String
Source§fn has_random_room(&self) -> bool
fn has_random_room(&self) -> bool
Returns true if the current sequence value can be incremented.
Source§fn next_random(&self) -> Self::Ty
fn next_random(&self) -> Self::Ty
Returns the next sequence value.
Source§fn increment_random(&self) -> Self
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
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.
impl Copy for ULID
impl Eq for ULID
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<ID> Base32Ext for ID
impl<ID> Base32Ext for ID
Source§fn encode_to_buf(&self, buf: &mut <<Self as Id>::Ty as BeBytes>::Base32Array)
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§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