UUID v4 generation and parsing for fastC.
Part of the fastc-core launch set. The implementation currently ships
inside the fastC compiler's built-in prelude — every fastC v1.0
program already gets use uuid::* for free. This repository is the
public home for the module's API and will become installable via
fastc add github.com/Skelf-Research/fastc-core-uuid once stage 1.7's
vendor-consumption flow completes the loop.
use uuid::Uuid; // struct Uuid { bytes: arr(u8, 16) }
use uuid::v4; // (cap: ref(CapRand)) -> Uuid
// RFC 4122 §4.4 random UUID
use uuid::nil; // () -> Uuid — the all-zero UUID
use uuid::parse; // (s: Str) -> opt(Uuid)
// 8-4-4-4-12 hex; None on malformed input
use uuid::format; // (u: Uuid) -> Str
// canonical lowercase hyphenated form
The canonical textual form is the 36-character lowercase hyphenated representation:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
parse accepts upper- or lowercase hex and returns None on any
malformed input (wrong length, wrong hyphen positions, non-hex
character). format always emits lowercase.
use uuid::v4;
use uuid::parse;
use uuid::format;
use caps::CapRand;
use io::println;
fn main(cap: ref(CapRand)) -> i32 {
let u: Uuid = v4(cap);
let s: Str = format(u);
println(s);
// Round-trip: format then parse yields the same value.
let back: opt(Uuid) = parse(s);
return 0;
}
v4 needs ref(CapRand) — the OS RNG is the source of randomness,
and every call to v4 is auditable through the capability surface.
nil, parse, and format are pure: they touch no ambient state
and require no capability token.
v0.1.0 — preview. API is final; the package becomes a true
installable via fastc add once the consumption flow ships. Until
then, the same API is available in every fastC v1.0 program via
the built-in prelude.
MIT