| Crates.io | init_static |
| lib.rs | init_static |
| version | 0.5.0 |
| created_at | 2025-11-03 09:07:03.248962+00 |
| updated_at | 2025-12-23 01:10:10.609133+00 |
| description | A Rust library for explicit static initialization. |
| homepage | |
| repository | https://github.com/shigma/init_static |
| max_upload_size | |
| id | 1914281 |
| size | 29,620 |
A Rust library for explicit static initialization.
init_static provides a macro similar to lazy_static, but with explicit initialization control. This means you decide when your statics are initialized, rather than having them lazily
evaluate on first use.
Unlike lazy_static, init_static uses std::sync::OnceLock internally and does not initialize your static values automatically. Instead, it gathers your initialization functions at compile-time using
linkme, and provides a function to run them all at once early in your program (for example, inside main()).
lazy_static| Feature | lazy_static |
init_static |
|---|---|---|
| Initialization | Implicit (on first use) | Explicit (init_static() call) |
Result support |
Not supported | Supported |
| Async support | Not supported | Supported |
| Early failure | No (fail at runtime) | Yes (optional, before app starts) |
Add this to your Cargo.toml:
[dependencies]
init_static = { version = "0.4" }
use init_static::init_static;
init_static! {
static VALUE: u32 = "42".parse()?;
}
#[tokio::main]
async fn main() {
init_static().await.unwrap();
println!("{}", *VALUE);
}