My intention was to create a singleton, but do not know how to handle this in Rust, I have read this and this, but not sure if that's the way to create a simple singleton because one speaks of a "mutable singleton" and the other of a "safe-static-singleton".
1 Answer
A singleton is just a lazily initialized piece of static data. That means you really do want lazy-static.
Note that
For a given
static ref NAME: TYPE = EXPR;, the macro generates a unique type that implementsDeref<TYPE>and stores it in a static with nameNAME.
which means NAME is actually akin to the constructor of the "singleton", and &*NAME is the "singleton" itself.
Mutex.