Skip to main content

Module id

Module id 

Source
Available on crate feature id only.
Expand description

ID generation — Rust port of du-node-utils/lib/id.js.

The function names track the Node original (snake-cased to match Rust conventions). UUIDs and nanoids are exposed on top as Rust-side conveniences.

§Node parity

NodeRust
id.makeUUID(false)uuid_v4
id.makeUUID(true)uuid_v4_simple
id.randomInt(min, max)random_int
id.randomString(len)random_string
id.makeUidPostfix()make_uid_postfix
id.makeUserId(a, u, c)make_user_id
id.parseUserid(s)parse_user_id
id.makeDbKey(uid)make_db_key
id.setSessionPrefix(p)set_session_prefix
id.generateSessionId()generate_session_id

Rust additions (no Node equivalent):

Structs§

UserId
Result of parse_user_id.

Constants§

DEFAULT_NANOID_LEN
Default nanoid length (matches the upstream library’s default).

Functions§

generate_session_id
Generate a session ID in the same format as Node’s generateSessionId: <prefix><13-digit ms timestamp><5-char base36 suffix>.
make_db_key
Build a database key in the form connect.<uid>.
make_uid_postfix
Generate a UID postfix: hex of (unix_ms * 1000 + random_in_0..1000).
make_user_id
Build a user ID in the form connect.<appid>.<uid>.<cuid>.
nanoid
Generate a nanoid of the default length (21 chars).
nanoid_with_alphabet
Generate a nanoid of a custom length and alphabet.
nanoid_with_len
Generate a nanoid of a custom length using the URL-safe alphabet.
parse_user_id
Parse a user ID produced by make_user_id. Returns None if the string has fewer than four .-separated segments.
random_int
Generate a random integer in the half-open range [min, max).
random_string
Generate a random string of length len using the same 36-char alphabet as Node’s id.randomString(len): 0-9 plus qwertyuioplkjhgfdsazxcvbnm (keyboard order).
set_session_prefix
Set a custom session prefix used by generate_session_id.
uuid_v4
Generate a random UUID v4 as a hyphenated string (36 chars).
uuid_v7
Generate a UUID v7 (time-ordered, monotonic per millisecond) as a hyphenated string.
uuid_v4_simple
Generate a random UUID v4 without hyphens (32 hex chars).
uuid_v7_simple
Generate a UUID v7 without hyphens.