get rid of lazy_static
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 17 Jun 2025 23:12:54 +0000 (16:12 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 17 Jun 2025 23:12:54 +0000 (16:12 -0700)
rust/Cargo.lock
rust/pspp/Cargo.toml
rust/pspp/build.rs
rust/pspp/src/macros.rs
rust/pspp/src/sys/encoding.rs

index 44608da21e03abde31977429319766505f6eba40..254f167ca3a30194a722b32170a8503b6b9e2230 100644 (file)
@@ -1124,12 +1124,6 @@ dependencies = [
  "wasm-bindgen",
 ]
 
-[[package]]
-name = "lazy_static"
-version = "1.5.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
-
 [[package]]
 name = "libc"
 version = "0.2.172"
@@ -1586,7 +1580,6 @@ dependencies = [
  "hexplay",
  "indexmap",
  "itertools",
- "lazy_static",
  "libc",
  "libm",
  "ndarray",
index 038d467bc24edea94b8abeb3e33b8b8a94662ef7..731595c284e57f7f144bcfc5b0654d945f121d7e 100644 (file)
@@ -10,7 +10,6 @@ clap = { version = "4.1.7", features = ["derive", "wrap_help"] }
 encoding_rs = "0.8.32"
 flate2 = "1.0.26"
 hexplay = "0.2.1"
-lazy_static = "1.4.0"
 num = "0.4.0"
 ordered-float = "3.7.0"
 thiserror = "1.0"
index 7805bc2895c57553ba89055145fc3c2f0af3c53d..240e4af4229e635c4d3466e2694826a052617128 100644 (file)
@@ -96,12 +96,10 @@ fn write_output(
 
     file.write_all(
         "\
-use lazy_static::lazy_static;
 use std::collections::HashMap;
 
-lazy_static! {
-    static ref CODEPAGE_NUMBER_TO_NAME: HashMap<i32, &'static str> = {
-        let mut map = HashMap::new();
+static CODEPAGE_NUMBER_TO_NAME: LazyLock<HashMap<i32, &'static str>> = LazyLock::new(|| {
+    let mut map = HashMap::new();
 "
         .as_bytes(),
     )?;
@@ -113,10 +111,10 @@ lazy_static! {
     }
     file.write_all(
         "        map
-    };
+});
 
-    static ref CODEPAGE_NAME_TO_NUMBER: HashMap<&'static str, u32> = {
-        let mut map = HashMap::new();
+static CODEPAGE_NAME_TO_NUMBER: LazyLock<HashMap<&'static str, u32>> = LazyLock::new(|| {
+    let mut map = HashMap::new();
 "
         .as_bytes(),
     )?;
@@ -142,8 +140,7 @@ lazy_static! {
     }
     file.write_all(
         "        map
-    };
-}
+});
 "
         .as_bytes(),
     )?;
index b2bc3f06fb09f0775300d14f663756744d5e7b48..2d295496401258ba89484d51ef24a322aa978cbf 100644 (file)
@@ -1,5 +1,4 @@
 #![allow(dead_code)]
-use lazy_static::lazy_static;
 use num::Integer;
 use std::{
     cell::RefCell,
@@ -8,6 +7,7 @@ use std::{
     mem::take,
     num::NonZeroUsize,
     ops::RangeInclusive,
+    sync::LazyLock,
 };
 use thiserror::Error as ThisError;
 use unicase::UniCase;
@@ -824,9 +824,7 @@ fn macro_keywords() -> HashSet<Identifier> {
 }
 
 fn is_macro_keyword(s: &Identifier) -> bool {
-    lazy_static! {
-        static ref KEYWORDS: HashSet<Identifier> = macro_keywords();
-    }
+    static KEYWORDS: LazyLock<HashSet<Identifier>> = LazyLock::new(macro_keywords);
     KEYWORDS.contains(s)
 }
 
@@ -1102,8 +1100,8 @@ impl Expander<'_> {
                 }
             }
         }
-        lazy_static! {
-            static ref MACRO_FUNCTIONS: [MacroFunction; 11] = [
+        static MACRO_FUNCTIONS: LazyLock<[MacroFunction; 11]> = LazyLock::new(|| {
+            [
                 MacroFunction::new("!BLANKS", 1..=1, Expander::expand_blanks),
                 MacroFunction::new("!CONCAT", 1..=usize::MAX, Expander::expand_concat),
                 MacroFunction::new("!HEAD", 1..=1, Expander::expand_head),
@@ -1115,8 +1113,8 @@ impl Expander<'_> {
                 MacroFunction::new("!UNQUOTE", 1..=1, Expander::expand_unquote),
                 MacroFunction::new("!UPCASE", 1..=1, Expander::expand_upcase),
                 MacroFunction::new("!EVAL", 1..=1, Expander::expand_eval),
-            ];
-        }
+            ]
+        });
 
         let function = MACRO_FUNCTIONS.iter().find(|mf| &mf.name == name)?;
 
index 7baf427a1e11cb1058afbb2c61d1ace968c76d00..26c1657f88e15b128089534a8e3db1b2b8b79b4e 100644 (file)
@@ -1,3 +1,5 @@
+use std::sync::LazyLock;
+
 use crate::locale_charset::locale_charset;
 use encoding_rs::{Encoding, UTF_8};
 
@@ -27,10 +29,8 @@ pub enum Error {
 }
 
 pub fn default_encoding() -> &'static Encoding {
-    lazy_static! {
-        static ref DEFAULT_ENCODING: &'static Encoding =
-            Encoding::for_label(locale_charset().as_bytes()).unwrap_or(UTF_8);
-    }
+    static DEFAULT_ENCODING: LazyLock<&'static Encoding> =
+        LazyLock::new(|| Encoding::for_label(locale_charset().as_bytes()).unwrap_or(UTF_8));
     &DEFAULT_ENCODING
 }