std/identifier
Identifiers: the trait Identifier and its two types, Uuid (RFC 9562, versions 4 and 7) and Ulid, one
IdentifierError for a text that is neither, and the urn:uuid: bridge to std/uri (docs/design/URI.md section
12).
The package is pure: randomness is a Random of std/random and the clock a Timestamp, both arguments, so it has
no capability and a test needs no mock. It is not in the prelude; a program that makes identifiers names it.
use Uuid from "std/identifier"
use Random from "std/random"
var source = Random.seeded 42
const identifier = Uuid.version7(source, at: Timestamp.fromUnixNanoseconds 1_790_000_000_000_000_000)
print identifier
Modules
std/identifier/errorIdentifierError: what a text is refused with when it is read as an identifier (docs/design/URI.md section 12).std/identifier/identifier[Identifier]: whatUuidandUlidhave in common (docs/design/URI.md section 12).std/identifier/ulid[Ulid]: a ULID, 128 bits of a millisecond and an 80-bit random part, shown as twenty-six characters of Crockford base 32 (docs/design/URI.md section 12).std/identifier/uuid[Uuid]: a UUID after RFC 9562, versions 4 and 7, and theurn:uuid:bridge tostd/uri(docs/design/URI.md section 12).
Everything
- trait
IdentifierWhat every identifier can do: it is 128 bits, shown as text, read back from it, compared bytewise and usable as the key of aMapor an element of aSet. - type
IdentifierErrorWhat a text that is not an identifier is refused with. - extend
String with From<Ulid>The twenty-six characters of a ULID. - extend
String with From<Uuid>The canonical text of a UUID. - type
UlidA ULID: sixteen bytes, the first six of them the milliseconds since 1970 and the last ten random, shown as twenty-six upper-case characters of Crockford base 32. - extend
Ulid with TryFrom<String, IdentifierError>Twenty-six characters of Crockford base 32, upper or lower case: the alphabet is the digits and the letters butI,L,OandU, and none of Crockford's aliases for1and0is read. - extend
Uri with From<Uuid>urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6, the URN namespace of RFC 9562 section 4: the bridge of [Uuid] tostd/uri, which has no dependency on this package. - type
UuidA UUID per RFC 9562: sixteen bytes, shown as the canonical thirty-six lower-case characters (f81d4fae-7dec-11d0-a765-00a0c91e6bf6). - extend
Uuid with TryFrom<String, IdentifierError>The thirty-six characters of a UUID of either case: eight, four, four, four and twelve hexadecimal digits separated by dashes. - extend
Uuid with TryFrom<Urn, IdentifierError>Aurn:uuid:URN read as a UUID.