Skip to content

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.

Cargo feature id (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features id

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.9", default-features = false, features = ["id"] }

Import path: helpers4::id.

ItemWhat it does
AlphabetThe characters a short id is made of: between 2 and 256 distinct characters.
new_short_idA short id of len characters drawn from an Alphabet with the operating system’s random source, every character equally likely.
short_idA short id of len characters drawn from an Alphabet with a seedable generator, every character equally likely.
UlidA ULID: 128 bits made of a 48-bit millisecond timestamp and 80 random bits, written as 26 characters of Crockford’s base32 (01ARYZ6S41TSV4RRFFQ69G5FAV).
UuidA UUID (RFC 9562): 128 bits, written xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.

Documented on the page of the helper that returns them.

TypeReturned by
AlphabetErrorAlphabet
ParseUlidErrorUlid
ParseUuidErrorUuid