Skip to content

Commit cfdb42a

Browse files
committed
Replace all once_cell uses with LazyLock.
See also scpwiki/wikijump#2473
1 parent 93a81e6 commit cfdb42a

File tree

19 files changed

+229
-215
lines changed

19 files changed

+229
-215
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ entities = "1"
3030
latex2mathml = { version = "0.2", optional = true }
3131
log = "0.4"
3232
maplit = "1"
33-
once_cell = "1.17.1"
3433
parcel_css = { version = "1.0.0-alpha.32", optional = true }
3534
parcel_selectors = "=0.24.7" # this is *not* a required dependency,
3635
# but we are pinning it since 0.24.8 does

src/includes/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,19 @@ use self::parse::parse_include_block;
3939
use crate::data::PageRef;
4040
use crate::settings::WikitextSettings;
4141
use crate::tree::VariableMap;
42-
use once_cell::sync::Lazy;
4342
use regex::{Regex, RegexBuilder};
43+
use std::sync::LazyLock;
4444

45-
static INCLUDE_REGEX: Lazy<Regex> = Lazy::new(|| {
45+
static INCLUDE_REGEX: LazyLock<Regex> = LazyLock::new(|| {
4646
RegexBuilder::new(r"^\[\[\s*include\s+")
4747
.case_insensitive(true)
4848
.multi_line(true)
4949
.dot_matches_new_line(true)
5050
.build()
5151
.unwrap()
5252
});
53-
static VARIABLE_REGEX: Lazy<Regex> =
54-
Lazy::new(|| Regex::new(r"\{\$(?P<name>[a-zA-Z0-9_\-]+)\}").unwrap());
53+
static VARIABLE_REGEX: LazyLock<Regex> =
54+
LazyLock::new(|| Regex::new(r"\{\$(?P<name>[a-zA-Z0-9_\-]+)\}").unwrap());
5555

5656
/// Replaces the include blocks in a string with the content of the pages referenced by those
5757
/// blocks.

src/info.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ pub use self::build::{
3131
RUSTC_VERSION, TARGET,
3232
};
3333

34-
use once_cell::sync::Lazy;
34+
use std::sync::LazyLock;
3535

36-
static VERSION_INFO: Lazy<String> = Lazy::new(|| {
36+
static VERSION_INFO: LazyLock<String> = LazyLock::new(|| {
3737
let mut version = format!("v{PKG_VERSION}");
3838

3939
if let Some(commit_hash) = *GIT_COMMIT_HASH_SHORT {
@@ -42,10 +42,13 @@ static VERSION_INFO: Lazy<String> = Lazy::new(|| {
4242

4343
version
4444
});
45+
4546
/// The package name and version info.
46-
pub static VERSION: Lazy<String> = Lazy::new(|| format!("{PKG_NAME} {}", *VERSION_INFO));
47+
pub static VERSION: LazyLock<String> =
48+
LazyLock::new(|| format!("{PKG_NAME} {}", *VERSION_INFO));
49+
4750
/// The full version info, including build information.
48-
pub static FULL_VERSION: Lazy<String> = Lazy::new(|| {
51+
pub static FULL_VERSION: LazyLock<String> = LazyLock::new(|| {
4952
let mut version = format!("{}\n\nCompiled:\n", *VERSION_INFO);
5053

5154
str_writeln!(&mut version, "* across {NUM_JOBS} threads");
@@ -56,11 +59,12 @@ pub static FULL_VERSION: Lazy<String> = Lazy::new(|| {
5659
version
5760
});
5861
/// The package name and full version info, including build information.
59-
pub static FULL_VERSION_WITH_NAME: Lazy<String> =
60-
Lazy::new(|| format!("{PKG_NAME} {}", *FULL_VERSION));
62+
pub static FULL_VERSION_WITH_NAME: LazyLock<String> =
63+
LazyLock::new(|| format!("{PKG_NAME} {}", *FULL_VERSION));
64+
6165
// The last 8 characters of the commit hash for this version.
62-
pub static GIT_COMMIT_HASH_SHORT: Lazy<Option<&'static str>> =
63-
Lazy::new(|| GIT_COMMIT_HASH.map(|s| &s[..8]));
66+
pub static GIT_COMMIT_HASH_SHORT: LazyLock<Option<&'static str>> =
67+
LazyLock::new(|| GIT_COMMIT_HASH.map(|s| &s[..8]));
6468

6569
#[test]
6670
fn info() {

src/parsing/rule/impls/block/blocks/char.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,24 @@
2020

2121
use super::prelude::*;
2222
use entities::ENTITIES;
23-
use once_cell::sync::Lazy;
2423
use std::borrow::Cow;
2524
use std::char;
2625
use std::collections::HashMap;
26+
use std::sync::LazyLock;
2727

28-
static ENTITY_MAPPING: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
29-
let mut mapping = HashMap::new();
28+
static ENTITY_MAPPING: LazyLock<HashMap<&'static str, &'static str>> =
29+
LazyLock::new(|| {
30+
let mut mapping = HashMap::new();
3031

31-
for entity in &ENTITIES {
32-
let key = strip_entity(entity.entity);
33-
let value = entity.characters;
32+
for entity in &ENTITIES {
33+
let key = strip_entity(entity.entity);
34+
let value = entity.characters;
3435

35-
mapping.insert(key, value);
36-
}
36+
mapping.insert(key, value);
37+
}
3738

38-
mapping
39-
});
39+
mapping
40+
});
4041

4142
pub const BLOCK_CHAR: BlockRule = BlockRule {
4243
name: "block-char",

src/parsing/rule/impls/block/blocks/date.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
use super::prelude::*;
2222
use crate::tree::DateItem;
23-
use once_cell::sync::Lazy;
2423
use regex::Regex;
24+
use std::sync::LazyLock;
2525
use time::format_description::well_known::{Iso8601, Rfc2822, Rfc3339};
2626
use time::{Date, OffsetDateTime, PrimitiveDateTime, UtcOffset};
2727

@@ -147,8 +147,8 @@ fn parse_date(value: &str) -> Result<DateItem, DateParseError> {
147147

148148
/// Parse the timezone based on the specifier string.
149149
fn parse_timezone(value: &str) -> Result<UtcOffset, DateParseError> {
150-
static TIMEZONE_REGEX: Lazy<Regex> =
151-
Lazy::new(|| Regex::new(r"^(\+|-)?([0-9]{1,2}):?([0-9]{2})?$").unwrap());
150+
static TIMEZONE_REGEX: LazyLock<Regex> =
151+
LazyLock::new(|| Regex::new(r"^(\+|-)?([0-9]{1,2}):?([0-9]{2})?$").unwrap());
152152

153153
debug!("Parsing possible timezone value '{value}'");
154154

src/parsing/rule/impls/block/blocks/module/mapping.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
*/
2020

2121
use super::{modules::*, ModuleRule};
22-
use once_cell::sync::Lazy;
2322
use std::collections::HashMap;
23+
use std::sync::LazyLock;
2424
use unicase::UniCase;
2525

2626
pub const MODULE_RULES: [ModuleRule; 6] = [
@@ -34,8 +34,8 @@ pub const MODULE_RULES: [ModuleRule; 6] = [
3434

3535
pub type ModuleRuleMap = HashMap<UniCase<&'static str>, &'static ModuleRule>;
3636

37-
pub static MODULE_RULE_MAP: Lazy<ModuleRuleMap> =
38-
Lazy::new(|| build_module_rule_map(&MODULE_RULES));
37+
pub static MODULE_RULE_MAP: LazyLock<ModuleRuleMap> =
38+
LazyLock::new(|| build_module_rule_map(&MODULE_RULES));
3939

4040
#[inline]
4141
pub fn get_module_rule_with_name(name: &str) -> Option<&'static ModuleRule> {

src/parsing/rule/impls/block/mapping.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
*/
2020

2121
use super::{blocks::*, BlockRule};
22-
use once_cell::sync::Lazy;
2322
use std::collections::HashMap;
23+
use std::sync::LazyLock;
2424
use unicase::UniCase;
2525

2626
pub const BLOCK_RULES: [BlockRule; 60] = [
@@ -88,8 +88,8 @@ pub const BLOCK_RULES: [BlockRule; 60] = [
8888

8989
pub type BlockRuleMap = HashMap<UniCase<&'static str>, &'static BlockRule>;
9090

91-
pub static BLOCK_RULE_MAP: Lazy<BlockRuleMap> =
92-
Lazy::new(|| build_block_rule_map(&BLOCK_RULES));
91+
pub static BLOCK_RULE_MAP: LazyLock<BlockRuleMap> =
92+
LazyLock::new(|| build_block_rule_map(&BLOCK_RULES));
9393

9494
#[inline]
9595
pub fn get_block_rule_with_name(name: &str) -> Option<&'static BlockRule> {

src/parsing/rule/impls/block/parser.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ use crate::parsing::{
2828
ParseResult, Parser, Token,
2929
};
3030
use crate::tree::Element;
31-
use once_cell::sync::Lazy;
3231
use regex::Regex;
32+
use std::sync::LazyLock;
3333

34-
static ARGUMENT_KEY: Lazy<Regex> = Lazy::new(|| Regex::new(r"[A-Za-z0-9_\-]+").unwrap());
34+
static ARGUMENT_KEY: LazyLock<Regex> =
35+
LazyLock::new(|| Regex::new(r"[A-Za-z0-9_\-]+").unwrap());
3536

3637
impl<'r, 't> Parser<'r, 't>
3738
where

src/parsing/rule/impls/color.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
*/
2020

2121
use super::prelude::*;
22-
use once_cell::sync::Lazy;
2322
use regex::Regex;
2423
use std::borrow::Cow;
24+
use std::sync::LazyLock;
2525

26-
static HEX_COLOR: Lazy<Regex> =
27-
Lazy::new(|| Regex::new(r"^([a-fA-F0-9]{3}|[a-fA-F0-9]{6})$").unwrap());
26+
static HEX_COLOR: LazyLock<Regex> =
27+
LazyLock::new(|| Regex::new(r"^([a-fA-F0-9]{3}|[a-fA-F0-9]{6})$").unwrap());
2828

2929
pub const RULE_COLOR: Rule = Rule {
3030
name: "color",

src/parsing/rule/impls/variable.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
*/
2020

2121
use super::prelude::*;
22-
use once_cell::sync::Lazy;
2322
use regex::Regex;
23+
use std::sync::LazyLock;
2424

25-
static VARIABLE_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"\{\$(.+)\}").unwrap());
25+
static VARIABLE_REGEX: LazyLock<Regex> =
26+
LazyLock::new(|| Regex::new(r"\{\$(.+)\}").unwrap());
2627

2728
pub const RULE_VARIABLE: Rule = Rule {
2829
name: "variable",

0 commit comments

Comments
 (0)