Skip to main content

init_static

Macro init_static 

Source
init_static!() { /* proc-macro */ }
Expand description

Macro to declare statically stored values with explicit initialization. Similar to lazy_static!, but initialization is not automatic.

Each static declared using this macro:

  • Wraps the value type in InitStatic
  • Generates an init function that sets the value
  • Registers the init function in a distributed slice

The values are initialized when init_static() is called.

ยงExample

use init_static::init_static;

init_static! {
    static VALUE: u32 = "42".parse()?;
}

#[tokio::main]
async fn main() {
    init_static().await.unwrap();
    println!("{}", *VALUE);
}