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
Copyright
License
Types 2
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 ...bool opEquals(const UUID s) @safe pure nothrow @nogc constAll of the standard numeric operators are defined for the UUID struct.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...this(ref const scope ubyte[16] uuidData)Construct a UUID struct from the 16 byte representation of a UUID.this(const ubyte[16] uuidData)dittothis(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(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-b52db3bdfb46VariantRFC 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.This exception is thrown if an error occurs when parsing a UUID from a string.
Reason reasondittostring inputThe original input string which should have been parsed.size_t positionThe position in the input string where the error occurred.this(string input, size_t pos, Reason why = Reason.unknown, string msg = "",
Throwable next = null, string file = __FILE__, size_t line = __LINE__)ReasonThe reason why parsing the UUID string failed (if known)Functions 10
UUID 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.UUID 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.UUID sha1UUID(scope const(ubyte)[] data, scope const UUID namespace = UUID.init) @safe pure nothrow @nogcdittoUUID randomUUID() @nogc nothrow @safeThis function generates a random number based UUID from a random number generator.UUID randomUUID(RNG)(ref RNG randomGen) if (isInputRange!RNG && isIntegral!(ElementType!RNG))dittoUUID 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:Variables 5
dnsNamespace = UUID("6ba7b810-9dad-11d1-80b4-00c04fd430c8")Default namespace from RFC 4122
Name string is a fully-qualified domain name
urlNamespace = UUID("6ba7b811-9dad-11d1-80b4-00c04fd430c8")Default namespace from RFC 4122
Name string is a URL
oidNamespace = UUID("6ba7b812-9dad-11d1-80b4-00c04fd430c8")Default namespace from RFC 4122
Name string is an ISO OID
x500Namespace = 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)
uuidRegex = "[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.