Skip to main content

generic_static

Macro generic_static 

Source
macro_rules! generic_static {
    {static $ident:ident $(: &$type:ty)? = &$init:expr;} => { ... };
}
Available on x86-64 or AArch64 or ARM or x86 only.
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 Sync type.

If this is executed for the first time in multiple threads simultaneously, the initializing expression may get executed multiple times.

§Example

fn generic_function<T>() {
    generic_static!{
        static NAME: &Mutex<String> = &Mutex::new("Ferris".to_string());
    }
    …
}