UlidId

Trait UlidId 

Source
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 { ... }
}
Available on crate feature ulid only.
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§

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: Self::Ty, random: Self::Ty) -> 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.

Provided Methods§

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.

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.

Implementors§