Skip to content

Commit 18fbd38

Browse files
committed
replace lazy_static with lazyLock
lazy_static is deprecated
1 parent 92a741c commit 18fbd38

File tree

31 files changed

+86
-89
lines changed

31 files changed

+86
-89
lines changed

Cargo.lock

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ name = "sentencex"
1616

1717
[dependencies]
1818
serde = { version = "1.0.228", features = ["derive"] }
19-
lazy_static = "1.5.0"
2019
regex = "1.12.2"
2120
clap = { version = "4.5.2", features = ["derive"] }
2221
serde_yaml = "0.9.33"
23-
once_cell = "1.21.3"
2422

2523
[dev-dependencies]
2624
criterion = { version = "0.7", features = ["html_reports"] }

src/constants.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,28 @@ pub fn get_quote_pairs() -> HashMap<&'static str, &'static str> {
2323
quote_pairs
2424
}
2525

26-
lazy_static::lazy_static! {
27-
pub static ref PARENS_REGEX: Regex = Regex::new(r"[\((<{\[](?:[^\)\]}>)]|\\[\)\]}>)])*[\)\]}>)]").unwrap();
28-
pub static ref EMAIL_REGEX: Regex = Regex::new(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}").unwrap();
29-
pub static ref NUMBERED_REFERENCE_REGEX: Regex = Regex::new(r"^(\s*\[\d+])+").unwrap();
30-
pub static ref SPACE_AFTER_SEPARATOR: Regex = Regex::new(r"^\s+").unwrap();
31-
pub static ref QUOTES_REGEX: Regex = {
32-
let quote_pairs = get_quote_pairs();
33-
let patterns: Vec<String> = quote_pairs
34-
.iter()
35-
.map(|(left, right)| format!(r"{}(\n|.)*?{}", regex::escape(left), regex::escape(right)))
36-
.collect();
37-
let quotes_regex_str = patterns.join("|");
38-
Regex::new(&quotes_regex_str).unwrap()
39-
};
40-
}
26+
use std::sync::LazyLock;
27+
28+
pub static PARENS_REGEX: LazyLock<Regex> =
29+
LazyLock::new(|| Regex::new(r"[\((<{\[](?:[^\)\]}>)]|\\[\)\]}>)])*[\)\]}>)]").unwrap());
30+
31+
pub static EMAIL_REGEX: LazyLock<Regex> =
32+
LazyLock::new(|| Regex::new(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}").unwrap());
33+
34+
pub static NUMBERED_REFERENCE_REGEX: LazyLock<Regex> =
35+
LazyLock::new(|| Regex::new(r"^(\s*\[\d+])+").unwrap());
36+
37+
pub static SPACE_AFTER_SEPARATOR: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^\s+").unwrap());
38+
39+
pub static QUOTES_REGEX: LazyLock<Regex> = LazyLock::new(|| {
40+
let quote_pairs = get_quote_pairs();
41+
let patterns: Vec<String> = quote_pairs
42+
.iter()
43+
.map(|(left, right)| format!(r"{}(\n|.)*?{}", regex::escape(left), regex::escape(right)))
44+
.collect();
45+
let quotes_regex_str = patterns.join("|");
46+
Regex::new(&quotes_regex_str).unwrap()
47+
});
4148

4249
pub const EXCLAMATION_WORDS: [&str; 17] = [
4350
"!Xũ",

src/languages/am.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use once_cell::sync::Lazy;
1+
use std::sync::LazyLock;
22

33
use super::Language;
44

55
#[derive(Debug, Clone)]
66
pub struct Amharic {}
7-
static AMHARIC_ABBREVIATIONS: Lazy<Vec<String>> = Lazy::new(|| {
7+
static AMHARIC_ABBREVIATIONS: LazyLock<Vec<String>> = LazyLock::new(|| {
88
include_str!("./abbrev/am.txt")
99
.lines()
1010
.chain(include_str!("./abbrev/am.txt").lines())

src/languages/ar.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use once_cell::sync::Lazy;
1+
use std::sync::LazyLock;
22

33
use super::Language;
44

55
#[derive(Debug, Clone)]
66
pub struct Arabic {}
7-
static ARABIC_ABBREVIATIONS: Lazy<Vec<String>> = Lazy::new(|| {
7+
static ARABIC_ABBREVIATIONS: LazyLock<Vec<String>> = LazyLock::new(|| {
88
include_str!("./abbrev/ar.txt")
99
.lines()
1010
.chain(include_str!("./abbrev/en.txt").lines())

src/languages/bg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use once_cell::sync::Lazy;
1+
use std::sync::LazyLock;
22

33
use super::Language;
44

55
#[derive(Debug, Clone)]
66
pub struct Bulgarian {}
7-
static BULGARIAN_ABBREVIATIONS: Lazy<Vec<String>> = Lazy::new(|| {
7+
static BULGARIAN_ABBREVIATIONS: LazyLock<Vec<String>> = LazyLock::new(|| {
88
include_str!("./abbrev/bg.txt")
99
.lines()
1010
.map(|line| line.trim().to_string())

src/languages/bn.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use once_cell::sync::Lazy;
1+
use std::sync::LazyLock;
22

33
use super::Language;
44

55
#[derive(Debug, Clone)]
66
pub struct Bengali {}
7-
static BENGALI_ABBREVIATIONS: Lazy<Vec<String>> = Lazy::new(|| {
7+
static BENGALI_ABBREVIATIONS: LazyLock<Vec<String>> = LazyLock::new(|| {
88
include_str!("./abbrev/bn.txt")
99
.lines()
1010
.chain(include_str!("./abbrev/en.txt").lines())

src/languages/ca.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use once_cell::sync::Lazy;
21
use regex::Regex;
2+
use std::sync::LazyLock;
33

44
use super::Language;
55

66
#[derive(Debug, Clone)]
77
pub struct Catalan {}
8-
static CATALAN_ABBREVIATIONS: Lazy<Vec<String>> = Lazy::new(|| {
8+
static CATALAN_ABBREVIATIONS: LazyLock<Vec<String>> = LazyLock::new(|| {
99
include_str!("./abbrev/es.txt")
1010
.lines()
1111
.map(|line| line.trim().to_string())

src/languages/da.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use once_cell::sync::Lazy;
21
use regex::Regex;
2+
use std::sync::LazyLock;
33

44
use super::Language;
55

66
#[derive(Debug, Clone)]
77
pub struct Danish {}
8-
static DANISH_ABBREVIATIONS: Lazy<Vec<String>> = Lazy::new(|| {
8+
static DANISH_ABBREVIATIONS: LazyLock<Vec<String>> = LazyLock::new(|| {
99
include_str!("./abbrev/da.txt")
1010
.lines()
1111
.map(|line| line.trim().to_string())

src/languages/de.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use once_cell::sync::Lazy;
1+
use std::sync::LazyLock;
22

33
use super::Language;
44

55
#[derive(Debug, Clone)]
66
pub struct Deutch {}
7-
static DEUTCH_ABBREVIATIONS: Lazy<Vec<String>> = Lazy::new(|| {
7+
static DEUTCH_ABBREVIATIONS: LazyLock<Vec<String>> = LazyLock::new(|| {
88
include_str!("./abbrev/de.txt")
99
.lines()
1010
.chain(include_str!("./abbrev/en.txt").lines())

0 commit comments

Comments
 (0)