macro_rules! generic_static {
{static $ident:ident $(: &$type:ty)? = &$init:expr;} => { ... };
}
Expand description
Declare a static variable that is not shared across different monomorphizations of the containing functions. Its type must be a shared reference to a type that implements Sync.
If this is executed for the first time in multiple threads simultaneously, the initializing expression may get executed multiple times.
On unsupported targets, this falls back to a hashmap and generic types from outer items may not be used.
On supported targets, the type annotation can be ommited.
ยงExample
generic_static!{
static NAME: &Mutex<String> = &Mutex::new("Ferris".to_string());
}