refactor: remove once_cell dependency and use std::sync equivalents (#4185)

This commit is contained in:
Falk Woldmann authored and GitHub committed 2025-05-25 16:09:56 +01:00
1 parent 1d954c2f6f
commit 3c3256ec02
22 files changed
+22 -47

No files matched your search

Generated
-11
View File
@@ -3734,7 +3734,6 @@ dependencies = [
"memoize", "memoize",
"notify", "notify",
"object 0.36.7", "object 0.36.7",
"once_cell",
"open", "open",
"path-absolutize", "path-absolutize",
"pdb", "pdb",
@@ -3911,9 +3910,6 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-core-types" name = "dioxus-core-types"
version = "0.7.0-alpha.0" version = "0.7.0-alpha.0"
dependencies = [
"once_cell",
]
[[package]] [[package]]
name = "dioxus-desktop" name = "dioxus-desktop"
@@ -3952,7 +3948,6 @@ dependencies = [
"ndk-sys 0.6.0+11769913", "ndk-sys 0.6.0+11769913",
"objc", "objc",
"objc_id", "objc_id",
"once_cell",
"rand 0.8.5", "rand 0.8.5",
"reqwest 0.12.15", "reqwest 0.12.15",
"rfd", "rfd",
@@ -4093,7 +4088,6 @@ dependencies = [
"futures-util", "futures-util",
"generational-box", "generational-box",
"hyper-rustls 0.27.5", "hyper-rustls 0.27.5",
"once_cell",
"parking_lot", "parking_lot",
"pin-project", "pin-project",
"rustls 0.23.27", "rustls 0.23.27",
@@ -4301,7 +4295,6 @@ dependencies = [
"dioxus-lib", "dioxus-lib",
"jni", "jni",
"libc", "libc",
"once_cell",
] ]
[[package]] [[package]]
@@ -4510,7 +4503,6 @@ dependencies = [
"hyper-rustls 0.27.5", "hyper-rustls 0.27.5",
"hyper-util", "hyper-util",
"inventory", "inventory",
"once_cell",
"parking_lot", "parking_lot",
"pin-project", "pin-project",
"rustls 0.23.27", "rustls 0.23.27",
@@ -4538,7 +4530,6 @@ dependencies = [
"futures-channel", "futures-channel",
"futures-util", "futures-util",
"generational-box", "generational-box",
"once_cell",
"parking_lot", "parking_lot",
"rand 0.8.5", "rand 0.8.5",
"reqwest 0.12.15", "reqwest 0.12.15",
@@ -5594,7 +5585,6 @@ dependencies = [
"dioxus", "dioxus",
"futures", "futures",
"futures-util", "futures-util",
"once_cell",
"serde", "serde",
"tokio", "tokio",
] ]
@@ -15943,7 +15933,6 @@ dependencies = [
"futures", "futures",
"getrandom 0.2.16", "getrandom 0.2.16",
"js-sys", "js-sys",
"once_cell",
"reqwest 0.12.15", "reqwest 0.12.15",
"wasm-bindgen", "wasm-bindgen",
"wasm-bindgen-futures", "wasm-bindgen-futures",
-1
View File
@@ -260,7 +260,6 @@ reqwest = "0.12.12"
owo-colors = "4.2.0" owo-colors = "4.2.0"
ciborium = "0.2.2" ciborium = "0.2.2"
base64 = "0.22.1" base64 = "0.22.1"
once_cell = "1.20.3"
uuid = "1.15.1" uuid = "1.15.1"
convert_case = "0.8.0" convert_case = "0.8.0"
tungstenite = { version = "0.26.2" } tungstenite = { version = "0.26.2" }
-1
View File
@@ -12,7 +12,6 @@ serde = { workspace = true }
futures = { workspace = true } futures = { workspace = true }
tokio = { workspace = true, optional = true } tokio = { workspace = true, optional = true }
futures-util.workspace = true futures-util.workspace = true
once_cell = { workspace = true }
[features] [features]
default = [] default = []
-1
View File
@@ -71,7 +71,6 @@ dunce = { workspace = true }
dirs = { workspace = true } dirs = { workspace = true }
reqwest = { workspace = true, features = ["rustls-tls", "trust-dns", "json"] } reqwest = { workspace = true, features = ["rustls-tls", "trust-dns", "json"] }
tower = { workspace = true } tower = { workspace = true }
once_cell = { workspace = true }
# path lookup # path lookup
which = { version = "7.0.2" } which = { version = "7.0.2" }
+2 -2
View File
@@ -3532,10 +3532,10 @@ impl BuildRequest {
/// ///
/// It's not guaranteed that they're different from any other folder /// It's not guaranteed that they're different from any other folder
pub(crate) fn prepare_build_dir(&self) -> Result<()> { pub(crate) fn prepare_build_dir(&self) -> Result<()> {
use once_cell::sync::OnceCell;
use std::fs::{create_dir_all, remove_dir_all}; use std::fs::{create_dir_all, remove_dir_all};
use std::sync::OnceLock;
static INITIALIZED: OnceCell<Result<()>> = OnceCell::new(); static INITIALIZED: OnceLock<Result<()>> = OnceLock::new();
let success = INITIALIZED.get_or_init(|| { let success = INITIALIZED.get_or_init(|| {
if self.platform != Platform::Server { if self.platform != Platform::Server {
+2 -2
View File
@@ -242,14 +242,14 @@ fn remove_triple_newlines(string: &str) -> String {
// #[cfg(test)] // #[cfg(test)]
// pub(crate) mod tests { // pub(crate) mod tests {
// use escargot::{CargoBuild, CargoRun}; // use escargot::{CargoBuild, CargoRun};
// use once_cell::sync::Lazy; // use std::sync::LazyLock;
// use std::fs::{create_dir_all, read_to_string}; // use std::fs::{create_dir_all, read_to_string};
// use std::path::{Path, PathBuf}; // use std::path::{Path, PathBuf};
// use std::process::Command; // use std::process::Command;
// use tempfile::tempdir; // use tempfile::tempdir;
// use toml::Value; // use toml::Value;
// static BINARY: Lazy<CargoRun> = Lazy::new(|| { // static BINARY: LazyLock<CargoRun> = LazyLock::new(|| {
// CargoBuild::new() // CargoBuild::new()
// .bin(env!("CARGO_BIN_NAME")) // .bin(env!("CARGO_BIN_NAME"))
// .current_release() // .current_release()
+2 -2
View File
@@ -24,8 +24,8 @@ use crate::{error::Result, Error, StructuredOutput};
use clap::builder::styling::{AnsiColor, Effects, Style, Styles}; use clap::builder::styling::{AnsiColor, Effects, Style, Styles};
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use html_parser::Dom; use html_parser::Dom;
use once_cell::sync::Lazy;
use serde::Deserialize; use serde::Deserialize;
use std::sync::LazyLock;
use std::{ use std::{
fmt::Display, fmt::Display,
fs::File, fs::File,
@@ -123,7 +123,7 @@ impl Display for Commands {
} }
} }
pub(crate) static VERSION: Lazy<String> = Lazy::new(|| { pub(crate) static VERSION: LazyLock<String> = LazyLock::new(|| {
format!( format!(
"{} ({})", "{} ({})",
crate::dx_build_info::PKG_VERSION, crate::dx_build_info::PKG_VERSION,
+2 -2
View File
@@ -1,7 +1,7 @@
use super::*; use super::*;
use crate::{AddressArguments, BuildArgs, TraceController}; use crate::{AddressArguments, BuildArgs, TraceController};
use futures_util::FutureExt; use futures_util::FutureExt;
use once_cell::sync::OnceCell; use std::sync::OnceLock;
use std::{backtrace::Backtrace, panic::AssertUnwindSafe}; use std::{backtrace::Backtrace, panic::AssertUnwindSafe};
/// Serve the project /// Serve the project
@@ -102,7 +102,7 @@ impl ServeArgs {
line: u32, line: u32,
column: u32, column: u32,
} }
static BACKTRACE: OnceCell<(Backtrace, Option<SavedLocation>)> = OnceCell::new(); static BACKTRACE: OnceLock<(Backtrace, Option<SavedLocation>)> = OnceLock::new();
// We *don't* want printing here, since it'll break the tui and log ordering. // We *don't* want printing here, since it'll break the tui and log ordering.
// //
+3 -3
View File
@@ -18,7 +18,7 @@ use crate::{serve::ServeUpdate, Cli, Commands, Platform as TargetPlatform, Verbo
use cargo_metadata::diagnostic::{Diagnostic, DiagnosticLevel}; use cargo_metadata::diagnostic::{Diagnostic, DiagnosticLevel};
use clap::Parser; use clap::Parser;
use futures_channel::mpsc::{unbounded, UnboundedReceiver, UnboundedSender}; use futures_channel::mpsc::{unbounded, UnboundedReceiver, UnboundedSender};
use once_cell::sync::OnceCell; use std::sync::OnceLock;
use std::{ use std::{
collections::HashMap, collections::HashMap,
env, env,
@@ -47,8 +47,8 @@ const LOG_FILE_NAME: &str = "dx.log";
const DX_SRC_FLAG: &str = "dx_src"; const DX_SRC_FLAG: &str = "dx_src";
static TUI_ACTIVE: AtomicBool = AtomicBool::new(false); static TUI_ACTIVE: AtomicBool = AtomicBool::new(false);
static TUI_TX: OnceCell<UnboundedSender<TraceMsg>> = OnceCell::new(); static TUI_TX: OnceLock<UnboundedSender<TraceMsg>> = OnceLock::new();
pub static VERBOSITY: OnceCell<Verbosity> = OnceCell::new(); pub static VERBOSITY: OnceLock<Verbosity> = OnceLock::new();
pub(crate) struct TraceController { pub(crate) struct TraceController {
pub(crate) tui_rx: UnboundedReceiver<TraceMsg>, pub(crate) tui_rx: UnboundedReceiver<TraceMsg>,
+3 -3
View File
@@ -1,6 +1,6 @@
use crate::{Result, TraceSrc}; use crate::{Result, TraceSrc};
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::sync::LazyLock;
use std::{fs, path::PathBuf, sync::Arc}; use std::{fs, path::PathBuf, sync::Arc};
use tracing::{error, trace, warn}; use tracing::{error, trace, warn};
@@ -33,8 +33,8 @@ pub(crate) struct CliSettings {
impl CliSettings { impl CliSettings {
/// Load the settings from the local, global, or default config in that order /// Load the settings from the local, global, or default config in that order
pub(crate) fn load() -> Arc<Self> { pub(crate) fn load() -> Arc<Self> {
static SETTINGS: Lazy<Arc<CliSettings>> = static SETTINGS: LazyLock<Arc<CliSettings>> =
Lazy::new(|| Arc::new(CliSettings::global_or_default())); LazyLock::new(|| Arc::new(CliSettings::global_or_default()));
SETTINGS.clone() SETTINGS.clone()
} }
-1
View File
@@ -11,4 +11,3 @@ keywords = ["dom", "ui", "gui", "react", ]
[dependencies] [dependencies]
once_cell = { workspace = true }
+2 -2
View File
@@ -1,7 +1,7 @@
use once_cell::sync::Lazy; use std::sync::LazyLock;
pub fn is_bundled_app() -> bool { pub fn is_bundled_app() -> bool {
static BUNDLED: Lazy<bool> = Lazy::new(|| { static BUNDLED: LazyLock<bool> = LazyLock::new(|| {
// If the env var is set, we're bundled // If the env var is set, we're bundled
if std::env::var("DIOXUS_CLI_ENABLED").is_ok() { if std::env::var("DIOXUS_CLI_ENABLED").is_ok() {
return true; return true;
-1
View File
@@ -47,7 +47,6 @@ futures-util = { workspace = true }
urlencoding = { workspace = true } urlencoding = { workspace = true }
async-trait = { workspace = true } async-trait = { workspace = true }
tao = { workspace = true, features = ["rwh_05"] } tao = { workspace = true, features = ["rwh_05"] }
once_cell = { workspace = true }
dioxus-history = { workspace = true } dioxus-history = { workspace = true }
base64 = { workspace = true } base64 = { workspace = true }
libc = "0.2.170" libc = "0.2.170"
+2 -3
View File
@@ -2,10 +2,9 @@
/// ///
/// We want to acquire this mutex before doing anything with the virtualdom directly /// We want to acquire this mutex before doing anything with the virtualdom directly
pub fn android_runtime_lock() -> std::sync::MutexGuard<'static, ()> { pub fn android_runtime_lock() -> std::sync::MutexGuard<'static, ()> {
use once_cell::sync::OnceCell; use std::sync::{Mutex, OnceLock};
use std::sync::Mutex;
static RUNTIME_LOCK: OnceCell<Mutex<()>> = OnceCell::new(); static RUNTIME_LOCK: OnceLock<Mutex<()>> = OnceLock::new();
RUNTIME_LOCK.get_or_init(|| Mutex::new(())).lock().unwrap() RUNTIME_LOCK.get_or_init(|| Mutex::new(())).lock().unwrap()
} }
-1
View File
@@ -41,7 +41,6 @@ dioxus-mobile = { workspace = true, optional = true }
tracing = { workspace = true } tracing = { workspace = true }
tracing-futures = { workspace = true, optional = true } tracing-futures = { workspace = true, optional = true }
once_cell = { workspace = true }
tokio-util = { workspace = true, features = ["rt"], optional = true } tokio-util = { workspace = true, features = ["rt"], optional = true }
async-trait = { workspace = true, optional = true } async-trait = { workspace = true, optional = true }
-2
View File
@@ -4,8 +4,6 @@
#![deny(missing_docs)] #![deny(missing_docs)]
#![cfg_attr(docsrs, feature(doc_cfg))] #![cfg_attr(docsrs, feature(doc_cfg))]
pub use once_cell;
#[cfg(all(feature = "web", feature = "document"))] #[cfg(all(feature = "web", feature = "document"))]
mod web; mod web;
-1
View File
@@ -15,7 +15,6 @@ dioxus-desktop = { workspace = true }
dioxus-lib = { workspace = true } dioxus-lib = { workspace = true }
dioxus-cli-config = { workspace = true } dioxus-cli-config = { workspace = true }
libc = "0.2.170" libc = "0.2.170"
once_cell = { workspace = true }
[target.'cfg(target_os = "android")'.dependencies] [target.'cfg(target_os = "android")'.dependencies]
jni = "0.21.1" jni = "0.21.1"
@@ -15,6 +15,5 @@ js-sys = { workspace = true }
wasm-bindgen = { workspace = true } wasm-bindgen = { workspace = true }
wasm-bindgen-futures = { workspace = true } wasm-bindgen-futures = { workspace = true }
web-sys = { workspace = true, features = ["Document", "Window", "HtmlElement", "Text", "DomRectReadOnly", "console"] } web-sys = { workspace = true, features = ["Document", "Window", "HtmlElement", "Text", "DomRectReadOnly", "console"] }
once_cell = { workspace = true }
getrandom = { workspace = true, features = ["js"] } getrandom = { workspace = true, features = ["js"] }
reqwest = { workspace = true, features = ["json"] } reqwest = { workspace = true, features = ["json"] }
-2
View File
@@ -39,7 +39,6 @@ dioxus-interpreter-js = { workspace = true, optional = true }
tracing = { workspace = true } tracing = { workspace = true }
tracing-futures = { workspace = true } tracing-futures = { workspace = true }
once_cell = { workspace = true }
async-trait = { workspace = true } async-trait = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
enumset = "1.1.5" enumset = "1.1.5"
@@ -108,4 +107,3 @@ aws-lc-rs = ["dep:aws-lc-rs"]
[package.metadata.docs.rs] [package.metadata.docs.rs]
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"] cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
features = ["axum", "web", "aws-lc-rs"] features = ["axum", "web", "aws-lc-rs"]
+2 -2
View File
@@ -6,10 +6,10 @@ use std::cell::RefCell;
use dioxus_lib::{document::*, prelude::*}; use dioxus_lib::{document::*, prelude::*};
use dioxus_ssr::Renderer; use dioxus_ssr::Renderer;
use once_cell::sync::Lazy;
use parking_lot::RwLock; use parking_lot::RwLock;
use std::sync::LazyLock;
static RENDERER: Lazy<RwLock<Renderer>> = Lazy::new(|| RwLock::new(Renderer::new())); static RENDERER: LazyLock<RwLock<Renderer>> = LazyLock::new(|| RwLock::new(Renderer::new()));
/// Reset the static renderer to a fresh state, clearing its cache. /// Reset the static renderer to a fresh state, clearing its cache.
pub(crate) fn reset_renderer() { pub(crate) fn reset_renderer() {
+2 -2
View File
@@ -331,7 +331,7 @@ pub(crate) fn add_server_context(
pub struct RenderHandleState { pub struct RenderHandleState {
config: ServeConfig, config: ServeConfig,
build_virtual_dom: Arc<dyn Fn() -> VirtualDom + Send + Sync>, build_virtual_dom: Arc<dyn Fn() -> VirtualDom + Send + Sync>,
ssr_state: once_cell::sync::OnceCell<SSRState>, ssr_state: std::sync::OnceLock<SSRState>,
} }
impl RenderHandleState { impl RenderHandleState {
@@ -364,7 +364,7 @@ impl RenderHandleState {
/// Set the [`SSRState`] for this [`RenderHandleState`]. Sharing a [`SSRState`] between multiple [`RenderHandleState`]s is more efficient than creating a new [`SSRState`] for each [`RenderHandleState`]. /// Set the [`SSRState`] for this [`RenderHandleState`]. Sharing a [`SSRState`] between multiple [`RenderHandleState`]s is more efficient than creating a new [`SSRState`] for each [`RenderHandleState`].
pub fn with_ssr_state(mut self, ssr_state: SSRState) -> Self { pub fn with_ssr_state(mut self, ssr_state: SSRState) -> Self {
self.ssr_state = once_cell::sync::OnceCell::new(); self.ssr_state = std::sync::OnceLock::new();
if self.ssr_state.set(ssr_state).is_err() { if self.ssr_state.set(ssr_state).is_err() {
panic!("SSRState already set"); panic!("SSRState already set");
} }
-1
View File
@@ -18,7 +18,6 @@ generational-box = { workspace = true }
tracing = { workspace = true } tracing = { workspace = true }
serde = { workspace = true, features = ["derive"], optional = true } serde = { workspace = true, features = ["derive"], optional = true }
parking_lot = { workspace = true} parking_lot = { workspace = true}
once_cell = { workspace = true}
rustc-hash = { workspace = true } rustc-hash = { workspace = true }
futures-channel = { workspace = true } futures-channel = { workspace = true }
futures-util = { workspace = true } futures-util = { workspace = true }