id
Unique identifiers without the uuid or ulid crates: Uuid (v4 random, v7 sortable by
time), Ulid, and short URL-safe ids over an Alphabet.
Randomness and time are parameters: Uuid::v4(random_bytes), Uuid::v7(unix_millis, random_bytes), Ulid::from_parts(unix_millis, random_bytes) and short_id(alphabet, len, &mut rng) are pure, so they are testable and work anywhere, wasm32-unknown-unknown
included. With the random-entropy feature, Uuid::new_v4, Uuid::new_v7, Ulid::new and
new_short_id take both from the operating system and the clock.
Ids made with a seeded Rng are reproducible, not secret.
Install
Section titled “Install”Cargo feature id (enabled by default). To compile only this module:
or in Cargo.toml:
Import path: helpers4::id.
| Item | What it does |
|---|---|
Alphabet | The characters a short id is made of: between 2 and 256 distinct characters. |
new_short_id | A short id of len characters drawn from an Alphabet with the operating system’s random source, every character equally likely. |
short_id | A short id of len characters drawn from an Alphabet with a seedable generator, every character equally likely. |
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). |
Uuid | A UUID (RFC 9562): 128 bits, written xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. |
Error types
Section titled “Error types”Documented on the page of the helper that returns them.
| Type | Returned by |
|---|---|
AlphabetError | Alphabet |
ParseUlidError | Ulid |
ParseUuidError | Uuid |
