Skip to content

std.uuid - ZZ

v4/v7 generation, parse (normalizing), validation. v7 is time-ordered — good for request IDs and DB keys.

import std.uuid

std.uuid generates UUID v4 (random) and v7 (time-ordered), parses and normalizes UUID strings, and validates shape. v7 sorts roughly by creation time — prefer it for IDs appearing in logs and indexes.

import std.uuid
println(uuid.v4()) // random, e.g. "f47ac10b-58cc-4372-a567-0e02b2c3d479"
println(uuid.v7()) // time-ordered (good for request IDs, DB keys)
s := uuid.v4()
println(uuid.parse(s)) // normalized or .err
println(uuid.is_valid(s)) // bool
import std.uuid
func main() -> Result<int, str> {
// Request ID for tracing
req_id := uuid.v7() // time-ordered, sortable in logs
println(req_id)
// External ID validation
external := "f47ac10b-58cc-4372-a567-0e02b2c3d479"
if uuid.is_valid(external) {
id := uuid.parse(external)?
println(id)
}
return .ok(0)
}

4 entries. Signatures come from the compiler’s own FuncSig table, so they match the runtime exactly; descriptions come from the module guide.

Function Signature Description
std.uuid.is_valid is_valid(s: str) -> bool Shape check
std.uuid.parse parse(s: str) -> Result<str, str> Normalize or .err
std.uuid.v4 v4() -> str Random UUID v4
std.uuid.v7 v7() -> str Time-ordered UUID v7
  • std.encoding — Codecs: base64, hex, URL encoding and JSON escaping.
  • std.crypto — Digests, HMAC, random bytes and password hashing.

Full index: API reference · Standard library