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
| Node | Rust |
|---|---|
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):
uuid_v7/uuid_v7_simple— time-ordered UUIDs.nanoid/nanoid_with_len/nanoid_with_alphabet— short URL-safe IDs.
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. ReturnsNoneif 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
lenusing the same 36-char alphabet as Node’sid.randomString(len):0-9plusqwertyuioplkjhgfdsazxcvbnm(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.