Skip to content

Commit 8a1f717

Browse files
authored
ref: Remove lazy_static dependency (#51)
This uses the std `LazyLock` instead of `lazy_static`.
1 parent 4851067 commit 8a1f717

File tree

5 files changed

+29
-26
lines changed

5 files changed

+29
-26
lines changed

Cargo.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@ readme = "README.md"
1111
edition = "2021"
1212

1313
[features]
14-
uuid = ["dep:uuid", "lazy_static"]
14+
uuid = ["dep:uuid"]
1515

1616
[dependencies]
17-
lazy_static = { version = "1.4.0", optional = true }
1817
thiserror = "1.0.61"
1918
uuid = { version = "1.0.0", features = ["v5"], optional = true }
2019
watto = { version = "0.1.0", features = ["writer", "strings"] }
2120

2221
[dev-dependencies]
23-
lazy_static = "1.4.0"
2422
criterion = "0.4"
2523

2624
[[bench]]

src/mapping.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,10 @@ impl<'s> ProguardMapping<'s> {
224224
/// The UUID is generated from a file checksum.
225225
#[cfg(feature = "uuid")]
226226
pub fn uuid(&self) -> Uuid {
227-
lazy_static::lazy_static! {
228-
static ref NAMESPACE: Uuid = Uuid::new_v5(&Uuid::NAMESPACE_DNS, b"guardsquare.com");
229-
}
227+
use std::sync::LazyLock;
228+
229+
static NAMESPACE: LazyLock<Uuid> =
230+
LazyLock::new(|| Uuid::new_v5(&Uuid::NAMESPACE_DNS, b"guardsquare.com"));
230231
// this internally only operates on bytes, so this is safe to do
231232
Uuid::new_v5(&NAMESPACE, self.source)
232233
}

tests/basic.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
use lazy_static::lazy_static;
1+
use std::sync::LazyLock;
22

33
use proguard::{ProguardCache, ProguardMapper, ProguardMapping, StackFrame};
44

55
static MAPPING: &[u8] = include_bytes!("res/mapping.txt");
6-
lazy_static! {
7-
static ref MAPPING_WIN: Vec<u8> = MAPPING
6+
7+
static MAPPING_WIN: LazyLock<Vec<u8>> = LazyLock::new(|| {
8+
MAPPING
89
.iter()
9-
.flat_map(|&byte| if byte == b'\n' {
10-
vec![b'\r', b'\n']
11-
} else {
12-
vec![byte]
10+
.flat_map(|&byte| {
11+
if byte == b'\n' {
12+
vec![b'\r', b'\n']
13+
} else {
14+
vec![byte]
15+
}
1316
})
14-
.collect();
15-
}
17+
.collect()
18+
});
1619

1720
#[test]
1821
fn test_basic() {

tests/r8.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
use lazy_static::lazy_static;
1+
use std::sync::LazyLock;
22

33
use proguard::{ProguardMapper, ProguardMapping, StackFrame};
44

55
static MAPPING_R8: &[u8] = include_bytes!("res/mapping-r8.txt");
66
static MAPPING_R8_SYMBOLICATED_FILE_NAMES: &[u8] =
77
include_bytes!("res/mapping-r8-symbolicated_file_names.txt");
88

9-
lazy_static! {
10-
static ref MAPPING_WIN_R8: Vec<u8> = MAPPING_R8
9+
static MAPPING_WIN_R8: LazyLock<Vec<u8>> = LazyLock::new(|| {
10+
MAPPING_R8
1111
.iter()
12-
.flat_map(|&byte| if byte == b'\n' {
13-
vec![b'\r', b'\n']
14-
} else {
15-
vec![byte]
12+
.flat_map(|&byte| {
13+
if byte == b'\n' {
14+
vec![b'\r', b'\n']
15+
} else {
16+
vec![byte]
17+
}
1618
})
17-
.collect();
18-
}
19+
.collect()
20+
});
1921

2022
#[test]
2123
fn test_basic_r8() {

0 commit comments

Comments
 (0)