Skip to content

Commit 764ae2f

Browse files
chore: replace once_cell OnceCell/Lazy with std OnceLock/LazyLock (#3709)
1 parent df47ffe commit 764ae2f

File tree

15 files changed

+44
-41
lines changed

15 files changed

+44
-41
lines changed

Cargo.lock

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

examples/postgres/axum-social-with-tests/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ validator = { version = "0.16.0", features = ["derive"] }
2424
# Auxilliary crates
2525
anyhow = "1.0.58"
2626
dotenvy = "0.15.1"
27-
once_cell = "1.13.0"
2827
thiserror = "2.0.0"
2928
tracing = "0.1.35"
3029

examples/postgres/axum-social-with-tests/src/http/user.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use axum::http::StatusCode;
22
use axum::{routing::post, Extension, Json, Router};
3-
use once_cell::sync::Lazy;
43
use rand::Rng;
54
use regex::Regex;
6-
use std::time::Duration;
5+
use std::{sync::LazyLock, time::Duration};
76

87
use serde::Deserialize;
98
use sqlx::{PgExecutor, PgPool};
@@ -18,7 +17,7 @@ pub fn router() -> Router {
1817
Router::new().route("/v1/user", post(create_user))
1918
}
2019

21-
static USERNAME_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^[0-9A-Za-z_]+$").unwrap());
20+
static USERNAME_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^[0-9A-Za-z_]+$").unwrap());
2221

2322
// CREATE USER
2423

sqlx-core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ futures-intrusive = "0.5.0"
6767
futures-util = { version = "0.3.19", default-features = false, features = ["alloc", "sink", "io"] }
6868
log = { version = "0.4.18", default-features = false }
6969
memchr = { version = "2.4.1", default-features = false }
70-
once_cell = "1.9.0"
7170
percent-encoding = "2.1.0"
7271
regex = { version = "1.5.5", optional = true }
7372
serde = { version = "1.0.132", features = ["derive", "rc"], optional = true }

sqlx-core/src/any/driver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use crate::connection::Connection;
55
use crate::database::Database;
66
use crate::Error;
77
use futures_core::future::BoxFuture;
8-
use once_cell::sync::OnceCell;
98
use std::fmt::{Debug, Formatter};
9+
use std::sync::OnceLock;
1010
use url::Url;
1111

12-
static DRIVERS: OnceCell<&'static [AnyDriver]> = OnceCell::new();
12+
static DRIVERS: OnceLock<&'static [AnyDriver]> = OnceLock::new();
1313

1414
#[macro_export]
1515
macro_rules! declare_driver_with_optional_migrate {

sqlx-macros-core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ dotenvy = { workspace = true }
6060
hex = { version = "0.4.3" }
6161
heck = { version = "0.5" }
6262
either = "1.6.1"
63-
once_cell = "1.9.0"
6463
proc-macro2 = { version = "1.0.79", default-features = false }
6564
serde = { version = "1.0.132", features = ["derive"] }
6665
serde_json = { version = "1.0.73" }

sqlx-macros-core/src/database/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::collections::hash_map;
22
use std::collections::HashMap;
3-
use std::sync::Mutex;
4-
5-
use once_cell::sync::Lazy;
3+
use std::sync::{LazyLock, Mutex};
64

75
use sqlx_core::connection::Connection;
86
use sqlx_core::database::Database;
@@ -30,14 +28,14 @@ pub trait DatabaseExt: Database + TypeChecking {
3028

3129
#[allow(dead_code)]
3230
pub struct CachingDescribeBlocking<DB: DatabaseExt> {
33-
connections: Lazy<Mutex<HashMap<String, DB::Connection>>>,
31+
connections: LazyLock<Mutex<HashMap<String, DB::Connection>>>,
3432
}
3533

3634
#[allow(dead_code)]
3735
impl<DB: DatabaseExt> CachingDescribeBlocking<DB> {
3836
pub const fn new() -> Self {
3937
CachingDescribeBlocking {
40-
connections: Lazy::new(|| Mutex::new(HashMap::new())),
38+
connections: LazyLock::new(|| Mutex::new(HashMap::new())),
4139
}
4240
}
4341

sqlx-macros-core/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ where
5757
{
5858
#[cfg(feature = "_rt-tokio")]
5959
{
60-
use once_cell::sync::Lazy;
60+
use std::sync::LazyLock;
61+
6162
use tokio::runtime::{self, Runtime};
6263

6364
// We need a single, persistent Tokio runtime since we're caching connections,
6465
// otherwise we'll get "IO driver has terminated" errors.
65-
static TOKIO_RT: Lazy<Runtime> = Lazy::new(|| {
66+
static TOKIO_RT: LazyLock<Runtime> = LazyLock::new(|| {
6667
runtime::Builder::new_current_thread()
6768
.enable_all()
6869
.build()

sqlx-macros-core/src/query/data.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ use std::fs;
44
use std::io::Write as _;
55
use std::marker::PhantomData;
66
use std::path::{Path, PathBuf};
7-
use std::sync::Mutex;
7+
use std::sync::{LazyLock, Mutex};
88

9-
use once_cell::sync::Lazy;
109
use serde::{Serialize, Serializer};
1110

1211
use sqlx_core::database::Database;
@@ -65,8 +64,8 @@ impl<DB: Database> Serialize for SerializeDbName<DB> {
6564
}
6665
}
6766

68-
static OFFLINE_DATA_CACHE: Lazy<Mutex<HashMap<PathBuf, DynQueryData>>> =
69-
Lazy::new(Default::default);
67+
static OFFLINE_DATA_CACHE: LazyLock<Mutex<HashMap<PathBuf, DynQueryData>>> =
68+
LazyLock::new(Default::default);
7069

7170
/// Offline query data
7271
#[derive(Clone, serde::Deserialize)]

sqlx-macros-core/src/query/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use std::collections::HashMap;
22
use std::path::{Path, PathBuf};
3-
use std::sync::{Arc, Mutex};
3+
use std::sync::{Arc, LazyLock, Mutex};
44
use std::{fs, io};
55

6-
use once_cell::sync::Lazy;
76
use proc_macro2::TokenStream;
87
use syn::Type;
98

@@ -108,7 +107,7 @@ impl Metadata {
108107
}
109108
}
110109

111-
static METADATA: Lazy<Mutex<HashMap<String, Metadata>>> = Lazy::new(Default::default);
110+
static METADATA: LazyLock<Mutex<HashMap<String, Metadata>>> = LazyLock::new(Default::default);
112111

113112
// If we are in a workspace, lookup `workspace_root` since `CARGO_MANIFEST_DIR` won't
114113
// reflect the workspace dir: https://github.com/rust-lang/cargo/issues/3946

0 commit comments

Comments
 (0)