macro_rules! magic_statics_mod {
{ $($vis:vis static ref $ident:ident: $ty:ty = $expr:expr;)* } => { ... };
}Expand description
The same as magic_static! but automatically generates the module-level magic_static function for you:
You can only have one of these per module (scope) - if you want to initialize magic statics in a group, define a magic_static function in your module yourself! (See the example)
ยงExample
mod foo {
// Note the use of `magic_statics_mod!` rather than `magic_static!` here
magic_statics_mod! {
pub(super) static ref MAGIC: usize = {
println!("Magic!");
42
};
pub(super) static ref BAR: std::sync::Mutex<()> = std::sync::Mutex::new(());
}
// Will generate the following:
/*
#[magic_static::main(
MAGIC,
BAR
)]
pub fn magic_static() {}
*/
}
#[magic_static::main(
mod foo // This will initialize all magic statics in `foo`
)]
fn main() {
println!("Hello, world!");
}