View source code
Display the source code in std/uuid.d from which thispage was generated on github.
Report a bug
If you spot a problem with this page, click here to create aGitHub 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 usinglocal clone.

Class std.uuid.MonotonicUUIDsFactoryImpl

class MonotonicUUIDsFactoryImpl(bool autostartDisabledForTesting);

Constructors

NameDescription
this (startTime)

Methods

NameDescription
createUUIDv7_method3 (externalRandom) Returns a monotonic timestamp + random based UUIDv7 as described in RFC 9562 (Method 3).
factory (classname) Create instance of class specified by the fully qualified name classname. The class must either have no constructors or have a default constructor.
opCmp (o) Compare with another Object obj.
opEquals (o) Test whether this is equal to o. The default implementation only compares by identity (using the is operator). Generally, overrides and overloads for opEquals should attempt to compare objects by their contents. A class will most likely want to add an overload that takes your specific type as the argument and does the content comparison. Then you can override this and forward it to your specific typed overload with a cast. Remember to check for null on the typed overload.
toHash () Compute hash function for Object.
toString () Convert Object to a human readable string.

Example

Read UUID v7 Method 3 timestamp

import core.time;
import std.datetime;

const u = UUID("019913ce-f124-7835-96c7-a2df691caa98");
const ts = u.v7Timestamp_method3;
const toCmp = SysTime(DateTime(2025, 9, 4, 8, 19, 13), dur!"hnsecs"(3165129), UTC());

writeln(ts); // toCmp

Example

Generate monotone UUIDs

import std.datetime.systime : Clock;
import core.time : abs, Duration, seconds;

auto f = new shared MonotonicUUIDsFactory;

UUID[10] monotonic;

foreach (ref u; monotonic)
{
    u = f.createUUIDv7_method3;

    const Duration d = Clock.currTime - u.v7Timestamp_method3;
    assert(d.abs < 1.seconds);
}

Authors

Johannes Pfau

License

Boost License 1.0.