]> Repositorios git - scryer-prolog.git/commitdiff
use a OnceLock static for LIBRARIES instead of thread_local! static
authorBennet Bleßmann <[email protected]>
Thu, 25 Jul 2024 16:58:29 +0000 (18:58 +0200)
committerBennet Bleßmann <[email protected]>
Thu, 25 Jul 2024 16:58:29 +0000 (18:58 +0200)
src/machine/mod.rs

index 12170e3993d2ade05a607456fa3bc03fbc91d22d..1726ae5b333d406b59b23da67e9320ffc534ed37 100644 (file)
@@ -120,23 +120,25 @@ fn current_dir() -> PathBuf {
 
 mod libraries {
     use indexmap::IndexMap;
+    use std::sync::OnceLock;
 
-    std::thread_local! {
-    static LIBRARIES: IndexMap<&'static str, &'static str> = {
+    fn libraries() -> &'static IndexMap<&'static str, &'static str> {
+        static LIBRARIES: OnceLock<IndexMap<&'static str, &'static str>> = OnceLock::new();
+        LIBRARIES.get_or_init(|| {
             let mut m = IndexMap::new();
 
             include!(concat!(env!("OUT_DIR"), "/libraries.rs"));
 
             m
-        }
+        })
     }
 
     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> {
-        LIBRARIES.with(|libs| libs.get(name).copied())
+        libraries().get(name).copied()
     }
 }