Crates.io | sly_static |
lib.rs | sly_static |
version | 1.0.6 |
source | src |
created_at | 2024-02-23 02:39:55.757391 |
updated_at | 2024-09-16 22:29:32.808756 |
description | Seamless Rust Static Initialization: Effortless and Efficient |
homepage | |
repository | https://github.com/Srlion/sly_static |
max_upload_size | |
id | 1149998 |
size | 3,834 |
Seamless Rust Static Initialization: Effortless and Efficient
This crate allows you to initialize static variables easily (automaticlly) inside main function.
Uses the linkme crate to collect all the static variables and initialize them inside the main function. It makes use of some code from ctor to initialize the statics.
It uses unsafe code to initialize the statics, but it's safe to use unless you do some weird magic with it.
I say it's safe because all the statics are initialized inside the main function, so there's no way to access them before they are initialized.
use sly_static::sly_static;
use sly_static::sly_main;
#[sly_static]
static MY_STATIC: String = String::from("Hello, World!");
#[sly_main]
fn main() {
println!("{}", *MY_STATIC);
}
License: MIT