pub trait UlidId: Id {
// Required methods
fn timestamp(&self) -> Self::Ty;
fn random(&self) -> Self::Ty;
fn max_timestamp() -> Self::Ty;
fn max_random() -> Self::Ty;
fn from_components(timestamp: Self::Ty, random: Self::Ty) -> Self;
fn is_valid(&self) -> bool;
fn into_valid(self) -> Self;
// Provided methods
fn has_random_room(&self) -> bool { ... }
fn next_random(&self) -> Self::Ty { ... }
fn increment_random(&self) -> Self { ... }
fn rollover_to_timestamp(&self, ts: Self::Ty, rand: Self::Ty) -> Self { ... }
}Expand description
Trait for layout-compatible ULID-style identifiers.
This trait abstracts a timestamp, random , and sequence partitions
over a fixed-size integer (e.g., u128) used for high-entropy time-sortable
ID generation.
Types implementing UlidId expose methods for construction, encoding, and
extracting field components from packed integers.
Required Methods§
Sourcefn max_timestamp() -> Self::Ty
fn max_timestamp() -> Self::Ty
Returns the maximum possible value for the timestamp field.
Sourcefn max_random() -> Self::Ty
fn max_random() -> Self::Ty
Returns the maximum possible value for the random field.
Sourcefn from_components(timestamp: Self::Ty, random: Self::Ty) -> Self
fn from_components(timestamp: Self::Ty, random: Self::Ty) -> Self
Constructs a new ULID from its components.
Sourcefn 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.
Sourcefn 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.
Provided Methods§
Sourcefn has_random_room(&self) -> bool
fn has_random_room(&self) -> bool
Returns true if the current sequence value can be incremented.
Sourcefn next_random(&self) -> Self::Ty
fn next_random(&self) -> Self::Ty
Returns the next sequence value.
Sourcefn increment_random(&self) -> Self
fn increment_random(&self) -> Self
Returns a new ID with the random portion incremented.
Sourcefn 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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.