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;
use std::error::Error;
init_static! {
static VALUE: u32 = "42".parse()?;
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
init_static().await?;
println!("{}", *VALUE);
Ok(())
}