use a OnceLock static for LIBRARIES instead of thread_local! static
This commit is contained in:
@@ -120,23 +120,25 @@ fn current_dir() -> PathBuf {
|
|||||||
|
|
||||||
mod libraries {
|
mod libraries {
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
std::thread_local! {
|
fn libraries() -> &'static IndexMap<&'static str, &'static str> {
|
||||||
static LIBRARIES: IndexMap<&'static str, &'static str> = {
|
static LIBRARIES: OnceLock<IndexMap<&'static str, &'static str>> = OnceLock::new();
|
||||||
|
LIBRARIES.get_or_init(|| {
|
||||||
let mut m = IndexMap::new();
|
let mut m = IndexMap::new();
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/libraries.rs"));
|
include!(concat!(env!("OUT_DIR"), "/libraries.rs"));
|
||||||
|
|
||||||
m
|
m
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn contains(name: &str) -> bool {
|
pub(crate) fn contains(name: &str) -> bool {
|
||||||
LIBRARIES.with(|libs| libs.contains_key(name))
|
libraries().contains_key(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get(name: &str) -> Option<&'static str> {
|
pub(crate) fn get(name: &str) -> Option<&'static str> {
|
||||||
LIBRARIES.with(|libs| libs.get(name).copied())
|
libraries().get(name).copied()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user