macro_rules! static_init {
($name:ident,$out:ty,$($init:tt)+) => { ... };
}Available on crate feature
std only.Expand description
Creates a static lazy initialization variable function.
static_init!(get_data, String, {
"This could be an expensive operation!".to_string()
});expands to:
pub fn get_data() -> &'static String {
static VARBL: std::sync::OnceLock<String> = std::sync::OnceLock::new();
VARBL.get_or_init(|| {
"This could be an expensive operation!".to_string()
})
}