From c37e3e39524189f47a549b39069071b4154f0154 Mon Sep 17 00:00:00 2001 From: frozenlib Date: Fri, 1 Dec 2023 22:48:01 +0900 Subject: [PATCH] Use std::sync::OnceLock in generated code and remove once_cell dependency. --- parse-display-derive/src/lib.rs | 5 ++--- parse-display/Cargo.toml | 3 +-- parse-display/src/lib.rs | 1 - 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/parse-display-derive/src/lib.rs b/parse-display-derive/src/lib.rs index 2dd4e89..4c884a9 100644 --- a/parse-display-derive/src/lib.rs +++ b/parse-display-derive/src/lib.rs @@ -562,9 +562,8 @@ impl<'a> ParserBuilder<'a> { let regex = to_regex_string(hirs); quote! { #[allow(clippy::trivial_regex)] - static RE: #crate_path::helpers::once_cell::sync::Lazy<#crate_path::helpers::regex::Regex> = - #crate_path::helpers::once_cell::sync::Lazy::new(|| #crate_path::helpers::regex::Regex::new(#regex).unwrap()); - if let Some(c) = RE.captures(&s) { + static RE: ::std::sync::OnceLock<#crate_path::helpers::regex::Regex> = ::std::sync::OnceLock::new(); + if let ::core::option::Option::Some(c) = RE.get_or_init(|| #crate_path::helpers::regex::Regex::new(#regex).unwrap()).captures(&s) { #code } } diff --git a/parse-display/Cargo.toml b/parse-display/Cargo.toml index 30f9a2a..b9171ca 100644 --- a/parse-display/Cargo.toml +++ b/parse-display/Cargo.toml @@ -13,9 +13,8 @@ edition = "2021" [dependencies] parse-display-derive = { version = "=0.8.2", path = "../parse-display-derive" } -once_cell = { version = "1.17.1", optional = true } regex = { version = "1.9.1", optional = true } [features] default = ["std"] -std = ["regex", "once_cell"] +std = ["regex"] diff --git a/parse-display/src/lib.rs b/parse-display/src/lib.rs index 9d75b47..91d2ea1 100644 --- a/parse-display/src/lib.rs +++ b/parse-display/src/lib.rs @@ -705,7 +705,6 @@ mod tests; #[cfg(feature = "std")] pub mod helpers { - pub use once_cell; pub use regex; }