From a291d7fca4cba28fbb942fc7e5458297005dea8f Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Wed, 25 Jun 2025 11:40:35 +0200 Subject: [PATCH] ref: Remove lazy_static dependency --- Cargo.lock | 3 +-- Cargo.toml | 4 +--- src/mapping.rs | 7 ++++--- tests/basic.rs | 21 ++++++++++++--------- tests/r8.rs | 20 +++++++++++--------- 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ee8633b..62f5d81 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "aho-corasick" @@ -337,7 +337,6 @@ name = "proguard" version = "5.5.0" dependencies = [ "criterion", - "lazy_static", "thiserror", "uuid", "watto", diff --git a/Cargo.toml b/Cargo.toml index 1dfb82c..2b78a09 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,16 +11,14 @@ readme = "README.md" edition = "2021" [features] -uuid = ["dep:uuid", "lazy_static"] +uuid = ["dep:uuid"] [dependencies] -lazy_static = { version = "1.4.0", optional = true } thiserror = "1.0.61" uuid = { version = "1.0.0", features = ["v5"], optional = true } watto = { version = "0.1.0", features = ["writer", "strings"] } [dev-dependencies] -lazy_static = "1.4.0" criterion = "0.4" [[bench]] diff --git a/src/mapping.rs b/src/mapping.rs index bdafe5a..016cf23 100644 --- a/src/mapping.rs +++ b/src/mapping.rs @@ -224,9 +224,10 @@ impl<'s> ProguardMapping<'s> { /// The UUID is generated from a file checksum. #[cfg(feature = "uuid")] pub fn uuid(&self) -> Uuid { - lazy_static::lazy_static! { - static ref NAMESPACE: Uuid = Uuid::new_v5(&Uuid::NAMESPACE_DNS, b"guardsquare.com"); - } + use std::sync::LazyLock; + + static NAMESPACE: LazyLock = + LazyLock::new(|| Uuid::new_v5(&Uuid::NAMESPACE_DNS, b"guardsquare.com")); // this internally only operates on bytes, so this is safe to do Uuid::new_v5(&NAMESPACE, self.source) } diff --git a/tests/basic.rs b/tests/basic.rs index a2499e5..0b0a565 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -1,18 +1,21 @@ -use lazy_static::lazy_static; +use std::sync::LazyLock; use proguard::{ProguardCache, ProguardMapper, ProguardMapping, StackFrame}; static MAPPING: &[u8] = include_bytes!("res/mapping.txt"); -lazy_static! { - static ref MAPPING_WIN: Vec = MAPPING + +static MAPPING_WIN: LazyLock> = LazyLock::new(|| { + MAPPING .iter() - .flat_map(|&byte| if byte == b'\n' { - vec![b'\r', b'\n'] - } else { - vec![byte] + .flat_map(|&byte| { + if byte == b'\n' { + vec![b'\r', b'\n'] + } else { + vec![byte] + } }) - .collect(); -} + .collect() +}); #[test] fn test_basic() { diff --git a/tests/r8.rs b/tests/r8.rs index 5cfdfc1..2d9e15d 100644 --- a/tests/r8.rs +++ b/tests/r8.rs @@ -1,4 +1,4 @@ -use lazy_static::lazy_static; +use std::sync::LazyLock; use proguard::{ProguardMapper, ProguardMapping, StackFrame}; @@ -6,16 +6,18 @@ static MAPPING_R8: &[u8] = include_bytes!("res/mapping-r8.txt"); static MAPPING_R8_SYMBOLICATED_FILE_NAMES: &[u8] = include_bytes!("res/mapping-r8-symbolicated_file_names.txt"); -lazy_static! { - static ref MAPPING_WIN_R8: Vec = MAPPING_R8 +static MAPPING_WIN_R8: LazyLock> = LazyLock::new(|| { + MAPPING_R8 .iter() - .flat_map(|&byte| if byte == b'\n' { - vec![b'\r', b'\n'] - } else { - vec![byte] + .flat_map(|&byte| { + if byte == b'\n' { + vec![b'\r', b'\n'] + } else { + vec![byte] + } }) - .collect(); -} + .collect() +}); #[test] fn test_basic_r8() {