INIT GUARD

The Init_Guard Crate provides a Synchronization Primitive, that can be used to guard against double initialization.

For this, the initguard macro is exported. The initguard macro creates a new module that contains everything needed for the init_guard.

The Module contains two public Methods, init() and has_init().

has_init()

The has_init function has the following definition:

fn has_init() -> bool

The hasinit function returns true, if the initguard was already initialized.

init()

The init function has the following definition:

fn init() -> Result<(),()>

The init function returns Ok, if the init_guard was succesfully initialized and Err, if it was already initialized before

Usage Example

``` initguard!(HASLOGGERINIT); // Create the initguard

fn initlogger() -> Result<(),String> { match HASLOGGERINIT::init() { Ok() => {}, Err() => {return Err("Logger is already initialized!".tostring())} } // Everything after this is now safe from double initialization

// Do your actual logger initialization here

} ```