View source code
Display the source code in std/uuid.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

std.uuid.UUID.this - multiple declarations

Function UUID.this

Construct a UUID struct from the 16 byte representation of a UUID.

ref this (
  ref const(ubyte[16]) uuidData
) pure nothrow @nogc @safe;

ref this (
  const(ubyte[16]) uuidData
) pure nothrow @nogc @safe;

Example

enum ubyte[16] data = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
auto uuid = UUID(data);
enum ctfe = UUID(data);
writeln(uuid.data); // data
writeln(ctfe.data); // data

Function UUID.this

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(T...) (
  T uuidData
) pure @safe
if (uuidData.length == 16 && allSatisfy!(isIntegral, T));

Example

auto tmp = UUID(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
assert(tmp.data == cast(ubyte[16])[0,1,2,3,4,5,6,7,8,9,10,11,
    12,13,14,15]);

Function UUID.this

Parse a UUID from its canonical string form. An UUID in its canonical form looks like this: 8ab3060e-2cba-4f23-b74c-b52db3bdfb46

this(T) (
  in T[] uuid
)
if (isSomeChar!T);

Throws

UUIDParsingException if the input is invalid

CTFE

This function is supported in CTFE code. Note that error messages caused by a malformed UUID parsed at compile time can be cryptic, but errors are detected and reported at compile time.

Note

This is a strict parser. It only accepts the pattern above. It doesn't support any leading or trailing characters. It only accepts characters used for hex numbers and the string must have hyphens exactly like above.

For a less strict parser, see parseUUID

Example

auto id = UUID("8AB3060E-2cba-4f23-b74c-b52db3bdfb46");
assert(id.data == [138, 179, 6, 14, 44, 186, 79, 35, 183, 76,
   181, 45, 179, 189, 251, 70]);
writeln(id.toString()); // "8ab3060e-2cba-4f23-b74c-b52db3bdfb46"

//Can also be used in CTFE, for example as UUID literals:
enum ctfeID = UUID("8ab3060e-2cba-4f23-b74c-b52db3bdfb46");
//here parsing is done at compile time, no runtime overhead!

Authors

Johannes Pfau

License

Boost License 1.0.