Skip to content

Commit e5b79bf

Browse files
committed
refactor: replace once_cell::sync::Lazy with std::sync::LazyLock
1 parent cfaa8ce commit e5b79bf

File tree

20 files changed

+137
-140
lines changed

20 files changed

+137
-140
lines changed

Cargo.lock

Lines changed: 0 additions & 3 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
@@ -72,7 +72,6 @@ mime = "0.3.17"
7272
num_cpus = "1.16"
7373
num-derive = "0.4"
7474
num-traits = { workspace = true }
75-
once_cell = { workspace = true }
7675
parking_lot = "0.12"
7776
percent-encoding = "2.3"
7877
pgp = { version = "0.15.0", default-features = false }
@@ -185,7 +184,6 @@ log = "0.4"
185184
mailparse = "0.16.1"
186185
nu-ansi-term = "0.46"
187186
num-traits = "0.2"
188-
once_cell = "1.21.3"
189187
rand = "0.8"
190188
regex = "1.10"
191189
rusqlite = "0.32"

deltachat-contact-tools/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ license = "MPL-2.0"
99

1010
[dependencies]
1111
anyhow = { workspace = true }
12-
once_cell = { workspace = true }
1312
regex = { workspace = true }
1413
rusqlite = { workspace = true } # Needed in order to `impl rusqlite::types::ToSql for EmailAddress`. Could easily be put behind a feature.
1514
chrono = { workspace = true, features = ["alloc", "clock", "std"] }

deltachat-contact-tools/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929

3030
use std::fmt;
3131
use std::ops::Deref;
32+
use std::sync::LazyLock;
3233

3334
use anyhow::bail;
3435
use anyhow::Context as _;
3536
use anyhow::Result;
3637
use chrono::{DateTime, NaiveDateTime};
37-
use once_cell::sync::Lazy;
3838
use regex::Regex;
3939

4040
#[derive(Debug)]
@@ -155,7 +155,8 @@ pub fn parse_vcard(vcard: &str) -> Vec<VcardContact> {
155155
}
156156

157157
// Remove line folding, see https://datatracker.ietf.org/doc/html/rfc6350#section-3.2
158-
static NEWLINE_AND_SPACE_OR_TAB: Lazy<Regex> = Lazy::new(|| Regex::new("\r?\n[\t ]").unwrap());
158+
static NEWLINE_AND_SPACE_OR_TAB: LazyLock<Regex> =
159+
LazyLock::new(|| Regex::new("\r?\n[\t ]").unwrap());
159160
let unfolded_lines = NEWLINE_AND_SPACE_OR_TAB.replace_all(vcard, "");
160161

161162
let mut lines = unfolded_lines.lines().peekable();
@@ -276,7 +277,8 @@ impl rusqlite::types::ToSql for ContactAddress {
276277
/// - Removes special characters from the name, see [`sanitize_name()`]
277278
/// - Removes the name if it is equal to the address by setting it to ""
278279
pub fn sanitize_name_and_addr(name: &str, addr: &str) -> (String, String) {
279-
static ADDR_WITH_NAME_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new("(.*)<(.*)>").unwrap());
280+
static ADDR_WITH_NAME_REGEX: LazyLock<Regex> =
281+
LazyLock::new(|| Regex::new("(.*)<(.*)>").unwrap());
280282
let (name, addr) = if let Some(captures) = ADDR_WITH_NAME_REGEX.captures(addr.as_ref()) {
281283
(
282284
if name.is_empty() {

deltachat-ffi/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ tokio = { workspace = true, features = ["rt-multi-thread"] }
2424
anyhow = { workspace = true }
2525
thiserror = { workspace = true }
2626
rand = { workspace = true }
27-
once_cell = { workspace = true }
2827
yerpc = { workspace = true, features = ["anyhow_expose"] }
2928

3029
[features]

deltachat-ffi/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::future::Future;
1818
use std::ops::Deref;
1919
use std::ptr;
2020
use std::str::FromStr;
21-
use std::sync::Arc;
21+
use std::sync::{Arc, LazyLock};
2222
use std::time::{Duration, SystemTime};
2323

2424
use anyhow::Context as _;
@@ -38,7 +38,6 @@ use deltachat::{accounts::Accounts, log::LogExt};
3838
use deltachat_jsonrpc::api::CommandApi;
3939
use deltachat_jsonrpc::yerpc::{OutReceiver, RpcClient, RpcSession};
4040
use num_traits::{FromPrimitive, ToPrimitive};
41-
use once_cell::sync::Lazy;
4241
use rand::Rng;
4342
use tokio::runtime::Runtime;
4443
use tokio::sync::RwLock;
@@ -68,7 +67,8 @@ const DC_GCM_INFO_ONLY: u32 = 0x02;
6867
/// Struct representing the deltachat context.
6968
pub type dc_context_t = Context;
7069

71-
static RT: Lazy<Runtime> = Lazy::new(|| Runtime::new().expect("unable to create tokio runtime"));
70+
static RT: LazyLock<Runtime> =
71+
LazyLock::new(|| Runtime::new().expect("unable to create tokio runtime"));
7272

7373
fn block_on<T>(fut: T) -> T::Output
7474
where

scripts/create-provider-data-rs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def process_dir(dir):
215215
" Config, ConfigDefault, Oauth2Authorizer, Provider, ProviderOptions, Server, Status,\n"
216216
"};\n"
217217
"use std::collections::HashMap;\n\n"
218-
"use once_cell::sync::Lazy;\n\n"
218+
"use std::sync::LazyLock;\n\n"
219219
)
220220

221221
process_dir(Path(sys.argv[1]))
@@ -224,7 +224,7 @@ def process_dir(dir):
224224
out_all += out_domains
225225
out_all += "];\n\n"
226226

227-
out_all += "pub(crate) static PROVIDER_IDS: Lazy<HashMap<&'static str, &'static Provider>> = Lazy::new(|| HashMap::from([\n"
227+
out_all += "pub(crate) static PROVIDER_IDS: LazyLock<HashMap<&'static str, &'static Provider>> = LazyLock::new(|| HashMap::from([\n"
228228
out_all += out_ids
229229
out_all += "]));\n\n"
230230

@@ -233,8 +233,8 @@ def process_dir(dir):
233233
else:
234234
now = datetime.datetime.fromisoformat(sys.argv[2])
235235
out_all += (
236-
"pub static _PROVIDER_UPDATED: Lazy<chrono::NaiveDate> = "
237-
"Lazy::new(|| chrono::NaiveDate::from_ymd_opt("
236+
"pub static _PROVIDER_UPDATED: LazyLock<chrono::NaiveDate> = "
237+
"LazyLock::new(|| chrono::NaiveDate::from_ymd_opt("
238238
+ str(now.year)
239239
+ ", "
240240
+ str(now.month)

src/authres.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
use std::borrow::Cow;
55
use std::collections::BTreeSet;
66
use std::fmt;
7+
use std::sync::LazyLock;
78

89
use anyhow::Result;
910
use deltachat_contact_tools::EmailAddress;
1011
use mailparse::MailHeaderMap;
1112
use mailparse::ParsedMail;
12-
use once_cell::sync::Lazy;
1313

1414
use crate::config::Config;
1515
use crate::context::Context;
@@ -107,7 +107,8 @@ fn remove_comments(header: &str) -> Cow<'_, str> {
107107
// In Pomsky, this is:
108108
// "(" Codepoint* lazy ")"
109109
// See https://playground.pomsky-lang.org/?text=%22(%22%20Codepoint*%20lazy%20%22)%22
110-
static RE: Lazy<regex::Regex> = Lazy::new(|| regex::Regex::new(r"\([\s\S]*?\)").unwrap());
110+
static RE: LazyLock<regex::Regex> =
111+
LazyLock::new(|| regex::Regex::new(r"\([\s\S]*?\)").unwrap());
111112

112113
RE.replace_all(header, " ")
113114
}

src/chatlist.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! # Chat list module.
22
33
use anyhow::{ensure, Context as _, Result};
4-
use once_cell::sync::Lazy;
4+
use std::sync::LazyLock;
55

66
use crate::chat::{update_special_chat_names, Chat, ChatId, ChatVisibility};
77
use crate::constants::{
@@ -17,8 +17,8 @@ use crate::summary::Summary;
1717
use crate::tools::IsNoneOrEmpty;
1818

1919
/// Regex to find out if a query should filter by unread messages.
20-
pub static IS_UNREAD_FILTER: Lazy<regex::Regex> =
21-
Lazy::new(|| regex::Regex::new(r"\bis:unread\b").unwrap());
20+
pub static IS_UNREAD_FILTER: LazyLock<regex::Regex> =
21+
LazyLock::new(|| regex::Regex::new(r"\bis:unread\b").unwrap());
2222

2323
/// An object representing a single chatlist in memory.
2424
///

src/constants.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
33
#![allow(missing_docs)]
44

5+
use std::sync::LazyLock;
6+
57
use deltachat_derive::{FromSql, ToSql};
6-
use once_cell::sync::Lazy;
78
use percent_encoding::{AsciiSet, NON_ALPHANUMERIC};
89
use serde::{Deserialize, Serialize};
910

1011
use crate::chat::ChatId;
1112

12-
pub static DC_VERSION_STR: Lazy<String> = Lazy::new(|| env!("CARGO_PKG_VERSION").to_string());
13+
pub static DC_VERSION_STR: LazyLock<String> =
14+
LazyLock::new(|| env!("CARGO_PKG_VERSION").to_string());
1315

1416
/// Set of characters to percent-encode in email addresses and names.
1517
pub(crate) const NON_ALPHANUMERIC_WITHOUT_DOT: &AsciiSet = &NON_ALPHANUMERIC.remove(b'.');

0 commit comments

Comments
 (0)