std.uuid

A UUID, or

Universally unique identifier,

is intended to uniquely identify information in a distributed environment without significant central coordination. It can be used to tag objects with very short lifetimes, or to reliably identify very persistent objects across a network.

UUIDs have many applications. Some examples follow: Databases may use UUIDs to identify rows or records in order to ensure that they are unique across different databases, or for publication/subscription services. Network messages may be identified with a UUID to ensure that different parts of a message are put back together again. Distributed computing may use UUIDs to identify a remote procedure call. Transactions and classes involved in serialization may be identified by UUIDs. Microsoft's component object model (COM) uses UUIDs to distinguish different software component interfaces. UUIDs are inserted into documents from Microsoft Office programs. UUIDs identify audio or video streams in the Advanced Systems Format (ASF). UUIDs are also a basis for OIDs (object identifiers), and URNs (uniform resource name).

An attractive feature of UUIDs when compared to alternatives is their relative small size, of 128 bits, or 16 bytes. Another is that the creation of UUIDs does not require a centralized authority.

When UUIDs are generated by one of the defined mechanisms, they are either guaranteed to be unique, different from all other generated UUIDs (that is, it has never been generated before and it will never be generated again), or it is extremely likely to be unique (depending on the mechanism).

For efficiency, UUID is implemented as a struct. UUIDs are therefore empty if not explicitly initialized. An UUID is empty if `UUID.empty` is true. Empty UUIDs are equal to UUID.init, which is a UUID with all 16 bytes set to 0. Use UUID's constructors or the UUID generator functions to get an initialized UUID.

This is a port of boost.uuid from the Boost project with some minor additions and API changes for a more D-like API.

Standards

Types 2

structUUID
Methods
Char toChar(Char)(size_t i) @safe pure nothrow @nogc const
T[16 / T.sizeof] asArrayOf(T)() if (isIntegral!T) @trusted ref return
bool empty() @trusted pure nothrow @nogc @property constReturns true if and only if the UUID is equal to {00000000-0000-0000-0000-000000000000}
SysTime v7Timestamp() constIf the UUID is of version 7 it has a timestamp that this function returns, otherwise and UUIDParsingException is thrown.
Variant variant() @safe pure nothrow @nogc @property constRFC 4122 defines different internal data layouts for UUIDs. Returns the format used by this UUID.
Version uuidVersion() @safe pure nothrow @nogc @property constRFC 4122 defines different UUID versions. The version shows how a UUID was generated, e.g. a version 4 UUID was generated from a random number, a version 3 UUID from an MD5 hash of a name. Returns ...
void swap(ref UUID rhs) @safe pure nothrow @nogcSwap the data of this UUID with the data of rhs.
bool opEquals(const UUID s) @safe pure nothrow @nogc constAll of the standard numeric operators are defined for the UUID struct.
bool opEquals(ref const scope UUID s) @safe pure nothrow @nogc constditto
int opCmp(const UUID s) @safe pure nothrow @nogc constditto
int opCmp(ref const scope UUID s) @safe pure nothrow @nogc constditto
UUID opAssign(const UUID s) @safe pure nothrow @nogcditto
UUID opAssign(ref const scope UUID s) @safe pure nothrow @nogcditto
size_t toHash() @safe pure nothrow @nogc constditto
void toString(Writer)(scope Writer sink) constWrite the UUID into `sink` as an ASCII string in the canonical form, which is 36 characters in the form "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" Params: sink = OutputRange or writeable array at least...
string toString() @trusted pure nothrow constReturn the UUID as a string in the canonical form.
Constructors
this(ref const scope ubyte[16] uuidData)Construct a UUID struct from the 16 byte representation of a UUID.
this(const ubyte[16] uuidData)ditto
this(T uuidData)Construct a UUID struct from the 16 byte representation of a UUID. Variadic constructor to allow a simpler syntax, see examples. You need to pass exactly 16 ubytes.
this(SysTime timestamp, ubyte[10] random = generateV7RandomData())UUID V7 constructor
this(in T[] uuid)<a name="UUID(string)"></a> Parse a UUID from its canonical string form. An UUID in its canonical form looks like this: 8ab3060e-2cba-4f23-b74c-b52db3bdfb46
Nested Templates
VariantRFC 4122 defines different internal data layouts for UUIDs. These are the UUID formats supported by this module. It's possible to read, compare and use all these Variants, but UUIDs generated by th...
VersionRFC 4122 defines different UUID versions. The version shows how a UUID was generated, e.g. a version 4 UUID was generated from a random number, a version 3 UUID from an MD5 hash of a name.
classUUIDParsingException : Exception

This exception is thrown if an error occurs when parsing a UUID from a string.

Fields
Reason reasonditto
string inputThe original input string which should have been parsed.
size_t positionThe position in the input string where the error occurred.
Constructors
this(string input, size_t pos, Reason why = Reason.unknown, string msg = "", Throwable next = null, string file = __FILE__, size_t line = __LINE__)
Nested Templates
ReasonThe reason why parsing the UUID string failed (if known)

Functions 10

fnUUID md5UUID(const(char[]) name, const UUID namespace = UUID.init) @safe pure nothrow @nogcThis function generates a name based (Version 3) UUID from a namespace UUID and a name. If no namespace UUID was passed, the empty UUID `UUID.init` is used.
fnUUID md5UUID(const(ubyte[]) data, const UUID namespace = UUID.init) @safe pure nothrow @nogcditto
fnUUID sha1UUID(scope const(char)[] name, scope const UUID namespace = UUID.init) @safe pure nothrow @nogcThis function generates a name based (Version 5) UUID from a namespace UUID and a name. If no namespace UUID was passed, the empty UUID `UUID.init` is used.
fnUUID sha1UUID(scope const(ubyte)[] data, scope const UUID namespace = UUID.init) @safe pure nothrow @nogcditto
fnUUID randomUUID() @nogc nothrow @safeThis function generates a random number based UUID from a random number generator.
fnUUID randomUUID(RNG)(ref RNG randomGen) if (isInputRange!RNG && isIntegral!(ElementType!RNG))ditto
fnUUID timestampRandomUUID()This function returns a timestamp + random based UUID aka. uuid v7.
fnUUID parseUUID(T)(T uuidString) if (isSomeString!T)This is a less strict parser compared to the parser used in the UUID constructor. It enforces the following rules:
fnUUID parseUUID(Range)(ref Range uuidRange) if (isInputRange!Range && isSomeChar!(ElementType!Range))ditto
private fnubyte[10] generateV7RandomData()

Variables 5

enumvardnsNamespace = UUID("6ba7b810-9dad-11d1-80b4-00c04fd430c8")

Default namespace from RFC 4122

Name string is a fully-qualified domain name

enumvarurlNamespace = UUID("6ba7b811-9dad-11d1-80b4-00c04fd430c8")

Default namespace from RFC 4122

Name string is a URL

enumvaroidNamespace = UUID("6ba7b812-9dad-11d1-80b4-00c04fd430c8")

Default namespace from RFC 4122

Name string is an ISO OID

enumvarx500Namespace = UUID("6ba7b814-9dad-11d1-80b4-00c04fd430c8")

Default namespace from RFC 4122

Name string is an X.500 DN (in DER or a text output format)

enumvaruuidRegex = "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}" ~ "-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"

Regex string to extract UUIDs from text.