pub struct ULID { /* private fields */ }Available on crate feature
ulid only.Expand description
A 128-bit ULID
- 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_BIT.
Sourcepub fn from_timestamp(timestamp: <Self as Id>::Ty) -> Self
Available on crate feature std only.
pub fn from_timestamp(timestamp: <Self as Id>::Ty) -> Self
std only.Generates a ULID from the given timestamp in milliseconds since
UNIX epoch, using the built-in ThreadRandom random
generator.
Sourcepub fn from_timestamp_and_rand<R>(timestamp: <Self as Id>::Ty, rng: &R) -> Self
pub fn from_timestamp_and_rand<R>(timestamp: <Self as Id>::Ty, rng: &R) -> Self
Generates a ULID from the given timestamp in milliseconds since
UNIX epoch and a custom random number generator implementing
RandSource
Sourcepub fn from_datetime(datetime: SystemTime) -> Self
Available on crate feature std only.
pub fn from_datetime(datetime: SystemTime) -> Self
std only.Generates a ULID from the given SystemTime, using the built-in
ThreadRandom random generator.
Sourcepub fn from_datetime_and_rand<R>(datetime: SystemTime, rng: &R) -> Self
Available on crate feature std only.
pub fn from_datetime_and_rand<R>(datetime: SystemTime, rng: &R) -> Self
std only.Generates a ULID from the given SystemTime and a custom random
number generator implementing RandSource
Trait Implementations§
Source§impl Ord for ULID
impl Ord for ULID
Source§impl PartialOrd for ULID
impl PartialOrd for ULID
Source§impl UlidId for ULID
impl UlidId 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.
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> Base32UlidExt for ID
impl<ID> Base32UlidExt for ID
Source§fn buf() -> <<Self as Id>::Ty as BeBytes>::Base32Array
fn buf() -> <<Self as Id>::Ty as BeBytes>::Base32Array
Available on crate features
base32 and ulid only.Returns a stack-allocated, zero-initialized buffer for Base32 encoding. Read more
Source§fn encode(&self) -> Base32UlidFormatter<Self>
fn encode(&self) -> Base32UlidFormatter<Self>
Available on crate features
base32 and ulid 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,
) -> Base32UlidFormatterRef<'buf, Self>
fn encode_to_buf<'buf>( &self, buf: &'buf mut <<Self as Id>::Ty as BeBytes>::Base32Array, ) -> Base32UlidFormatterRef<'buf, Self>
Available on crate features
base32 and ulid only.Encodes this ID into the provided buffer without heap allocation and
returns a formatter view over the buffer similar to
Base32UlidExt::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