RFC 9562 UUID library for MoonBit with v3-v8, monotonic v7, secure generation, and binary/text interop
Dependencies
moon add wulisususu/moonuuid@0.1.0import {
"wulisususu/moonuuid" @uuid
}match @uuid.v7() {
Ok(id) => println(@uuid.to_string(id))
Err(_) => println("secure entropy unavailable")
}let id = @uuid.v5_string(
@uuid.namespace_url(),
"https://example.com/users/42",
)
println(@uuid.to_string(id))let strict = @uuid.parse(
"017f22e2-79b0-7cc3-98c4-dc0c0c07398f",
)
let interoperable = @uuid.parse_permissive(
"urn:uuid:017f22e2-79b0-7cc3-98c4-dc0c0c07398f",
)let generator = @uuid.V7Generator::new()
let next_id = generator.next()| Capability | Status | Main API |
|---|---|---|
| Canonical parse/format | ✅ | parse, to_string |
| Compact / URN / braced text | ✅ | parse_permissive, to_urn, to_braced_string |
| 16-byte network-order interop | ✅ | to_bytes, from_bytes |
| UUIDv3 | ✅ | v3, v3_string |
| UUIDv4 | ✅ | v4, v4_with_entropy, v4_from_entropy |
| UUIDv5 | ✅ | v5, v5_string |
| UUIDv6 | ✅ | v6_from_parts |
| UUIDv7 | ✅ | v7, v7_with, v7_from_parts |
| Monotonic UUIDv7 | ✅ | V7Generator |
| UUIDv8 custom fields | ✅ | v8_from_parts |
| SHA-256 UUIDv8 profile | ✅ | v8_sha256, v8_sha256_string |
| Standard namespaces | ✅ | DNS / URL / OID / X.500 |
| Nil / Max / version / variant | ✅ | inspection helpers |
| RFC vectors | ✅ | v3 / v4 / v5 / v6 / v7 / v8 |
| Cross-target CI | ✅ | wasm / wasm-gc / js / Linux native / Windows native |
moon run examples/web_request_id --target native
moon run examples/database_key --target native
moon run examples/deterministic_resource_id --target native
moon run examples/interop --target nativemoon bench benchmarks --release --target native --deny-warnmoon fmt --check
moon check --target <wasm|wasm-gc|js|native> --deny-warn
moon test --target <wasm|wasm-gc|js|native>
moon build --target <wasm|wasm-gc|js|native>
moon info --target native
moon package --list
moon bench benchmarks --release --target native --deny-warnpub(all) enum ParseError {
InvalidLength(Int)
InvalidHyphen(Int)
InvalidHexDigit(Int)
InvalidWrapper
} derive(Eq)pub(all) enum V6Error {
TimestampOutOfRange(UInt64)
ClockSeqOutOfRange(UInt64)
NodeOutOfRange(UInt64)
} derive(Eq)pub(all) enum V7Error {
EntropyUnavailable
InvalidEntropyLength(Int)
TimestampOutOfRange(UInt64)
RandAOutOfRange(UInt64)
RandBOutOfRange(UInt64)
MonotonicOverflow
} derive(Eq)pub struct V7Generator {
initialized : Bool
last_ms : UInt64
rand_a : UInt64
rand_b : UInt64
}fn V7Generator::next_with(self : V7Generator, clock : () -> UInt64, entropy : (Int) -> Bytes?) -> Result[Uuid, V7Error]pub(all) enum V8Error {
CustomAOutOfRange(UInt64)
CustomBOutOfRange(UInt64)
CustomCOutOfRange(UInt64)
} derive(Eq)fn is_valid(text : String) -> Boolfn is_valid_permissive(text : String) -> BoolInstall
Download zipRFC 9562 UUID library for MoonBit with v3-v8, monotonic v7, secure generation, and binary/text interop
Dependencies