Ulid
A ULID: 128 bits made of a 48-bit millisecond timestamp and 80 random bits, written as 26
characters of Crockford’s base32 (01ARYZ6S41TSV4RRFFQ69G5FAV).
Ulids sort by creation time, both as numbers and as text, and are shorter than a UUID. Time
and randomness are parameters of from_parts; with the
random-entropy feature, new takes them from the system. Ids made in the
same millisecond are not ordered among themselves (there is no monotonic counter).
Import
Section titled “Import”Cargo feature id (enabled by default). To compile only this module:
or in Cargo.toml:
Definition
Section titled “Definition”Examples
Section titled “Examples”Methods
Section titled “Methods”Reads a ULID from its 26-character form, in upper or lower case. Only the 32 symbols of
Crockford’s base32 are accepted (I, L, O and U are not).
Parameters
| Parameter | Type | Description |
|---|---|---|
text | &str | The text to read. |
Returns
Result<Self, ParseUlidError> — The ULID.
Errors
Returns a ParseUlidError for a length other than 26, a character outside the
alphabet, or a first character above 7 (the value would not fit in 128 bits).
Examples
A ULID with the current time from the system clock and random bits from the operating system.
Needs the random-entropy feature. A clock set before 1970 gives a timestamp of 0.
Returns
Result<Self, crate::random::EntropyError> — The ULID.
Errors
Returns an EntropyError when the operating system cannot
provide random bytes.
Examples
Error type: ParseUlidError
Section titled “Error type: ParseUlidError”Why a string is not a Ulid.
