Skip to content

Commit eab5bbe

Browse files
authored
Merge pull request #2473 from scpwiki/lazylock
Use LazyLock instead of once_cell
2 parents 4ee7114 + c22ba51 commit eab5bbe

File tree

8 files changed

+23
-24
lines changed

8 files changed

+23
-24
lines changed

deepwell/Cargo.lock

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

deepwell/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ intl-memoizer = "0.5"
4040
jsonrpsee = { version = "0.24", features = ["macros", "server"] }
4141
log = "0.4"
4242
notify = { version = "8", optional = true }
43-
once_cell = "1"
4443
paste = "1"
4544
rand = "0.8"
4645
redis = { version = "0.28", features = ["aio", "connection-manager", "keep-alive", "tokio-comp", "tokio-rustls-comp"] }

deepwell/src/info.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ mod build {
2222
include!(concat!(env!("OUT_DIR"), "/built.rs"));
2323
}
2424

25-
use once_cell::sync::Lazy;
25+
use std::sync::LazyLock;
2626
use time::format_description::well_known::Rfc2822;
2727
use time::OffsetDateTime;
2828

@@ -33,12 +33,12 @@ pub use self::build::{
3333
RUSTC_VERSION, TARGET,
3434
};
3535

36-
pub static BUILT_TIME_UTC: Lazy<OffsetDateTime> = Lazy::new(|| {
36+
pub static BUILT_TIME_UTC: LazyLock<OffsetDateTime> = LazyLock::new(|| {
3737
OffsetDateTime::parse(BUILT_TIME_UTC_STR, &Rfc2822)
3838
.expect("Unable to parse built time string")
3939
});
4040

41-
pub static VERSION_INFO: Lazy<String> = Lazy::new(|| {
41+
pub static VERSION_INFO: LazyLock<String> = LazyLock::new(|| {
4242
let mut version = format!("v{PKG_VERSION}");
4343

4444
if let Some(commit_hash) = *GIT_COMMIT_HASH_SHORT {
@@ -48,7 +48,7 @@ pub static VERSION_INFO: Lazy<String> = Lazy::new(|| {
4848
version
4949
});
5050

51-
pub static COMPILE_INFO: Lazy<String> = Lazy::new(|| {
51+
pub static COMPILE_INFO: LazyLock<String> = LazyLock::new(|| {
5252
let mut info = str!("Compile info:\n");
5353
str_writeln!(&mut info, "* on {BUILT_TIME_UTC_STR}");
5454
str_writeln!(&mut info, "* by {RUSTC_VERSION}");
@@ -57,15 +57,16 @@ pub static COMPILE_INFO: Lazy<String> = Lazy::new(|| {
5757
info
5858
});
5959

60-
pub static VERSION: Lazy<String> = Lazy::new(|| format!("{PKG_NAME} {}", *VERSION_INFO));
60+
pub static VERSION: LazyLock<String> =
61+
LazyLock::new(|| format!("{PKG_NAME} {}", *VERSION_INFO));
6162

62-
pub static FULL_VERSION: Lazy<String> =
63-
Lazy::new(|| format!("{}\n\n{}", *VERSION, *COMPILE_INFO));
63+
pub static FULL_VERSION: LazyLock<String> =
64+
LazyLock::new(|| format!("{}\n\n{}", *VERSION, *COMPILE_INFO));
6465

65-
pub static GIT_COMMIT_HASH_SHORT: Lazy<Option<&'static str>> =
66-
Lazy::new(|| build::GIT_COMMIT_HASH.map(|s| &s[..8]));
66+
pub static GIT_COMMIT_HASH_SHORT: LazyLock<Option<&'static str>> =
67+
LazyLock::new(|| build::GIT_COMMIT_HASH.map(|s| &s[..8]));
6768

68-
pub static HOSTNAME: Lazy<String> = Lazy::new(|| {
69+
pub static HOSTNAME: LazyLock<String> = LazyLock::new(|| {
6970
// According to the gethostname(3p) man page,
7071
// there don't seem to be any errors possible.
7172
//

deepwell/src/services/blob/mime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
//! Evaluates MIME types using libmagic.
2222
//!
2323
//! Because it is a binding to a C library, it cannot be shared among threads.
24-
//! So we cannot use `once_cell::Lazy` and we can't have it in a coroutine.
24+
//! So we cannot use `LazyLock` and we can't have it in a coroutine.
2525
//! We don't load the `Magic` instance locally because it's an expensive operation
2626
//! and it would be inefficient to load it for each invocation.
2727
//!

deepwell/src/services/file/service.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ use crate::services::filter::{FilterClass, FilterType};
3535
use crate::services::{BlobService, FileRevisionService, FilterService, PageService};
3636
use crate::types::FileOrder;
3737
use crate::utils::regex_replace_in_place;
38-
use once_cell::sync::Lazy;
3938
use regex::Regex;
4039
use sea_orm::ActiveValue;
40+
use std::sync::LazyLock;
4141

4242
pub const MAXIMUM_FILE_NAME_LENGTH: usize = 256;
4343

44-
static LEADING_TRAILING_SPACES: Lazy<Regex> =
45-
Lazy::new(|| Regex::new(r"(^\s+)|(\s+$)").unwrap());
44+
static LEADING_TRAILING_SPACES: LazyLock<Regex> =
45+
LazyLock::new(|| Regex::new(r"(^\s+)|(\s+$)").unwrap());
4646

4747
#[derive(Debug)]
4848
pub struct FileService;

deepwell/src/services/file_revision/service.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ use crate::models::{file, page, site};
2727
use crate::services::blob::{FinalizeBlobUploadOutput, EMPTY_BLOB_HASH, EMPTY_BLOB_MIME};
2828
use crate::services::{BlobService, OutdateService, PageService};
2929
use crate::types::{Bytes, FetchDirection};
30-
use once_cell::sync::Lazy;
3130
use sea_orm::{prelude::*, FromQueryResult};
3231
use std::num::NonZeroI32;
32+
use std::sync::LazyLock;
3333

3434
/// The changes for the first revision.
3535
/// The first revision is always considered to have changed everything.
3636
///
3737
/// See `services/page_revision/service.rs`.
38-
static ALL_CHANGES: Lazy<Vec<String>> =
39-
Lazy::new(|| vec![str!("page"), str!("name"), str!("blob"), str!("mime")]);
38+
static ALL_CHANGES: LazyLock<Vec<String>> =
39+
LazyLock::new(|| vec![str!("page"), str!("name"), str!("blob"), str!("mime")]);
4040

4141
#[derive(Debug)]
4242
pub struct FileRevisionService;

deepwell/src/services/page_revision/service.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ use crate::utils::{split_category, split_category_name};
3434
use ftml::data::PageInfo;
3535
use ftml::layout::Layout;
3636
use ftml::settings::{WikitextMode, WikitextSettings};
37-
use once_cell::sync::Lazy;
3837
use ref_map::*;
3938
use std::num::NonZeroI32;
39+
use std::sync::LazyLock;
4040

4141
/// The changes for the first revision.
4242
/// The first revision is always considered to have changed everything.
4343
///
4444
/// See `services/file_revision/service.rs`.
45-
static ALL_CHANGES: Lazy<Vec<String>> = Lazy::new(|| {
45+
static ALL_CHANGES: LazyLock<Vec<String>> = LazyLock::new(|| {
4646
vec![
4747
str!("wikitext"),
4848
str!("title"),

deepwell/src/services/user/service.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ use crate::services::email::{EmailClassification, EmailService};
2727
use crate::services::filter::{FilterClass, FilterType};
2828
use crate::services::{AliasService, FilterService, PasswordService};
2929
use crate::utils::regex_replace_in_place;
30-
use once_cell::sync::Lazy;
3130
use regex::Regex;
3231
use sea_orm::ActiveValue;
3332
use std::cmp;
33+
use std::sync::LazyLock;
3434

35-
static LEADING_TRAILING_CHARS: Lazy<Regex> =
36-
Lazy::new(|| Regex::new(r"(^[\-\s]+)|([\-\s+]$)").unwrap());
35+
static LEADING_TRAILING_CHARS: LazyLock<Regex> =
36+
LazyLock::new(|| Regex::new(r"(^[\-\s]+)|([\-\s+]$)").unwrap());
3737

3838
#[derive(Debug)]
3939
pub struct UserService;

0 commit comments

Comments
 (0)