std.uuid
The UUIDs of RFC 9562: identifiers of 128 bits that are made without asking anyone, written as 550e8400-e29b-41d4-a716-446655440000.
import std.uuid
uuid.Uuid id = uuid.v4() // random: the one for most uses
println("{}", id) // 3f2b8c1e-9d4a-4f6b-a1c2-7e5d9b0f4a36
uuid.Uuid row = uuid.v7() // with the time in front: sorted as they are made
uuid.Uuid same = uuid.v5(uuid.namespaceUrl(), "https://cromolang.org") // always the same for a name
uuid.Uuid read = uuid.parse("550e8400-e29b-41d4-a716-446655440000")
if (read == id) { ... }The guide: Files, processes and time.
Made from the documentation in the sources of the library.
#Types
#Variant
enum VariantWhich family of UUIDs one is of, from the bits after its version.
Ncs: of the Apollo Network Computing System, before the standardRfc9562: of the standard: all those made hereMicrosoft: the GUIDs of the old COMFuture: kept for later
#Uuid
struct UuidA UUID: 16 bytes, high the first eight and low the last eight, the first byte at the top of each. Printed with {} it is its text, and two are compared with ==. One declared without a value is the nil UUID, all zeros.
u64 highu64 low
#Uuid.text
string text() constThe UUID as 36 characters, with lower-case digits: 550e8400-e29b-41d4-a716-446655440000.
#Uuid.bytes
list<u8> bytes() constThe 16 bytes of the UUID, in the order of its text.
#Uuid.isNil
bool isNil() constWhether it is the nil UUID, all zeros: the one that stands for no UUID.
#Uuid.version
i64 version() constThe version, 1 to 8 for a UUID of the standard: 4 for a random one, 7 for one with the time in front. It is the first digit of the third group of the text.
#Uuid.variant
Variant variant() constThe family of the UUID: Variant.Rfc9562 for those of the standard.
#Uuid.compare
i64 compare(Uuid other) const-1, 0 or 1 when this UUID comes before other, is the same or comes after it, in the order of the bytes: the order of the texts, and for the versions 6 and 7 the order in which they were made.
#Functions
#nil
Uuid nil()The nil UUID, all zeros.
#max
Uuid max()The max UUID, all ones: ffffffff-ffff-ffff-ffff-ffffffffffff.
#namespaceDns
Uuid namespaceDns()The namespace of the names of DNS, as "cromolang.org", for v3 and v5.
#namespaceUrl
Uuid namespaceUrl()The namespace of the URLs, for v3 and v5.
#namespaceOid
Uuid namespaceOid()The namespace of the OIDs of ISO, for v3 and v5.
#namespaceX500
Uuid namespaceX500()The namespace of the names of X.500, for v3 and v5.
#fromBytes
Uuid fromBytes(list<u8> bytes)The UUID of 16 bytes, in the order of its text. Throws an Error when the bytes are not 16.
#isValid
bool isValid(string text)Whether text is a UUID that parse reads.
#parse
Uuid parse(string text)The UUID written in text: 550e8400-e29b-41d4-a716-446655440000, or its 32 digits without the -, in upper or lower case. Throws an Error for another text.
#v4
Uuid v4()A random UUID, of version 4: 122 bits from the generator of the system. The one to use when nothing else is asked.
#v7
Uuid v7()A UUID of version 7: the milliseconds of the time of the system in front, then 74 random bits. Those made later come after in the order of compare and of the texts, which keeps the index of a database compact; two of the same millisecond are in no order.
#v1
Uuid v1()A UUID of version 1: the time of the system in intervals of 100 nanoseconds, a random sequence and a random node in place of the address of the network card, so that it says nothing of the computer. For the systems that ask this version: a new program uses v7.
#v6
Uuid v6()A UUID of version 6: as v1, with the time written from its highest part, so that those made later come after.
#v5
Uuid v5(Uuid space, string name)The UUID of a name in a namespace, of version 5: always the same for the same two, from their SHA-1. The namespace is namespaceDns(), namespaceUrl() or any UUID of the program.
#v3
Uuid v3(Uuid space, string name)The UUID of a name in a namespace, of version 3: as v5 with MD5, for the systems that ask this version.
#v8
Uuid v8(list<u8> bytes)A UUID of version 8, with the 16 bytes of the program: the version and the variant take 6 bits of them, the other 122 are kept. Throws an Error when the bytes are not 16.