cromo La guida di Cromo
Scarica PDF EN

std.uuid

The UUIDs of RFC 9562: identifiers of 128 bits that are made without asking anyone, written as 550e8400-e29b-41d4-a716-446655440000.

cromo
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.

Generata dalla documentazione nei sorgenti della libreria, che è in inglese.

#Tipi

#Variant

cromo
enum Variant

Which family of UUIDs one is of, from the bits after its version.

  • Ncs: of the Apollo Network Computing System, before the standard
  • Rfc9562: of the standard: all those made here
  • Microsoft: the GUIDs of the old COM
  • Future: kept for later

#Uuid

cromo
struct Uuid

A 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 high
  • u64 low

#Uuid.text

cromo
string text() const

The UUID as 36 characters, with lower-case digits: 550e8400-e29b-41d4-a716-446655440000.

#Uuid.bytes

cromo
list<u8> bytes() const

The 16 bytes of the UUID, in the order of its text.

#Uuid.isNil

cromo
bool isNil() const

Whether it is the nil UUID, all zeros: the one that stands for no UUID.

#Uuid.version

cromo
i64 version() const

The 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

cromo
Variant variant() const

The family of the UUID: Variant.Rfc9562 for those of the standard.

#Uuid.compare

cromo
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.

#Funzioni

#nil

cromo
Uuid nil()

The nil UUID, all zeros.

#max

cromo
Uuid max()

The max UUID, all ones: ffffffff-ffff-ffff-ffff-ffffffffffff.

#namespaceDns

cromo
Uuid namespaceDns()

The namespace of the names of DNS, as "cromolang.org", for v3 and v5.

#namespaceUrl

cromo
Uuid namespaceUrl()

The namespace of the URLs, for v3 and v5.

#namespaceOid

cromo
Uuid namespaceOid()

The namespace of the OIDs of ISO, for v3 and v5.

#namespaceX500

cromo
Uuid namespaceX500()

The namespace of the names of X.500, for v3 and v5.

#fromBytes

cromo
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

cromo
bool isValid(string text)

Whether text is a UUID that parse reads.

#parse

cromo
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

cromo
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

cromo
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

cromo
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

cromo
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

cromo
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

cromo
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

cromo
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.