lazyinit
Initialize a static value lazily.
Unlike lazy_static
, which hardcodes the initialization routine in a macro, you can initialize the value in any way.
Examples
use LazyInit;
static VALUE: = new;
assert!;
// println!("{}", *VALUE); // panic: use uninitialized value
assert_eq!;
VALUE.init_once;
// VALUE.init_once(666); // panic: already initialized
assert!;
assert_eq!;
assert_eq!;
Only one of the multiple initializations can succeed:
use LazyInit;
use Duration;
const N: usize = 16;
static VALUE: = new;
let threads =
.map
.;
let mut ok = 0;
for in threads.into_iter.enumerate
assert_eq!;