Macro generic_static_cache::generic_static
source · 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.
Only available on supported targets; to support all platforms use fallback_generic_static
.
Example
#![feature(const_collections_with_hasher)]
generic_static!{
static NAME = &Mutex::new("Ferris".to_string());
}
// If the type cannot be infered, you can annotate it:
generic_static!{
static IDS: &Mutex<Vec<i32>> = &Mutex::new(Vec::new());
}