128BITmoonuuididentifier notes
MoonBit · RFC 9562
MoonBit · RFC 9562

UUIDs,
written down.

Read any spelling, write the canonical one, and make ids from a name, from a clock, or from a random source. Time comes in as a function and randomness as a moonrand source you pass, so the same code runs on every backend.

$moon add moonbitstack/moonuuid
make onelive
{{ p.text }}—

{{ error }}

compiled from MoonBit, running in this page
7versionsevery one the RFC defines
128bitsone fixed width
5spellingsread from text
16octetskept in order

the layout

One width, five fields

Every identifier is 128 bits written as five groups. The group sizes never change; what the bits mean depends on the version.

c232ab00-9414-11ec-b3c8-9f6bdeced846
time_lowtime_midversion + time_hiclock_seqnode

what is here

Six things the library does

01

Every version, one type

Time-based, name-based, random and custom identifiers all come back as the same Uuid. One parser and one set of writers cover every version.

02

A generator you feed

Generator::new takes a clock and a random source. It keeps the counters, so versions 1 and 6 never repeat and version 7 sorts in the order made.

03

Fields you can read

version, variant, time, clock_seq and node read the bits back as values, not as a string you slice.

04

Text in, text out

Canonical, plain hex, braces or urn:uuid:, in any case. to_string, hex and urn write it back.

05

JSON without glue

A UUID is a JSON string on the way out and any spelling on the way in, with no wrapper type to write.

06

Refusals with reasons

Malformed points at the character that stopped the parse. Size gives the two lengths. Nothing fails silently.

start

Take it for a run

Ten minutes of guide, or the reference when you know what you are looking for.