Macro global_static::ctor_static
source · macro_rules! ctor_static { () => { ... }; ($($body:tt)*) => { ... }; }
Available on crate feature
ctor
only.Expand description
Generate a static with a ctor procedure.
fn spit_a_number() -> i32 { 42 }
ctor_static! {
pub MY_NUM: i32 = { 5 };
MY_OTHER_NUM: i32 = spit_a_number;
pub default DEFAULT_NUM: i32;
};
This code will expand to the following:
pub static MY_NUM: Global<i32> = Global::new(|| { 5 });
static MY_OTHER_NUM: Global<i32> = Global::new(spit_a_number);
pub static DEFAULT_NUM: Global<i32> = Global::default();
#[global_static::ctor::ctor]
fn _global_init() {
MY_NUM.init();
MY_OTHER_NUM.init();
DEFAULT_NUM.init();
}