From 65aa9280fbf2d369a00b253e99927ae4a64bc321 Mon Sep 17 00:00:00 2001 From: Rastler3D Date: Mon, 9 Dec 2024 19:58:06 +0400 Subject: [PATCH] Use std::sync::LazyLock instead of once_cell::sync::Lazy --- Cargo.toml | 1 - README.md | 2 +- examples/regexes/src/main.rs | 2 +- src/lib.rs | 6 +++--- src/proc_macros/mod.rs | 10 +++++----- src/proc_macros/regex_code.rs | 4 ++-- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 32afaae..361d7a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,6 @@ readme = "README.md" rust-version = "1.56" [dependencies] -once_cell = "1.17" regex = {version = "1.9", default-features = false, optional = true} regex-lite = {version = "0.1", optional = true} diff --git a/README.md b/README.md index e28d4e9..f330cf7 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ With lazy-regex macros, regular expressions * are checked at compile time, with clear error messages -* are wrapped in `once_cell` lazy static initializers so that they're compiled only once +* are wrapped in `std` lazy static initializers so that they're compiled only once * can hold flags as suffix: `let case_insensitive_regex = regex!("ab*"i);` * are defined in a less verbose way diff --git a/examples/regexes/src/main.rs b/examples/regexes/src/main.rs index 665d06d..cdc1f61 100644 --- a/examples/regexes/src/main.rs +++ b/examples/regexes/src/main.rs @@ -1,6 +1,6 @@ use lazy_regex::*; -pub static SHARED: Lazy = lazy_regex!("^test$"); +pub static SHARED: LazyLock = lazy_regex!("^test$"); fn example_builds() { // build a simple regex diff --git a/src/lib.rs b/src/lib.rs index e9346e8..3472c6d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,7 @@ With lazy-regex macros, regular expressions * are checked at compile time, with clear error messages -* are wrapped in `once_cell` lazy static initializers so that they're compiled only once +* are wrapped in `std` lazy static initializers so that they're compiled only once * can hold flags as suffix: `let case_insensitive_regex = regex!("ab*"i);` * are defined in a less verbose way @@ -195,7 +195,7 @@ If you want to have a shared lazy static regex, use the [lazy_regex!] macro: ```rust use lazy_regex::*; -pub static GLOBAL_REX: Lazy = lazy_regex!("^ab+$"i); +pub static GLOBAL_REX: LazyLock = lazy_regex!("^ab+$"i); ``` Like for the other macros, the regex is static, checked at compile time, and lazily built at first use. @@ -225,7 +225,7 @@ pub use { bytes_regex_replace_all, bytes_regex_switch, }, - once_cell::sync::Lazy, + std::sync::LazyLock }; #[cfg(not(feature = "lite"))] diff --git a/src/proc_macros/mod.rs b/src/proc_macros/mod.rs index 3d01c68..bd444ba 100644 --- a/src/proc_macros/mod.rs +++ b/src/proc_macros/mod.rs @@ -67,14 +67,14 @@ pub fn bytes_regex(input: TokenStream) -> TokenStream { process(input, true, |regex_code| regex_code.lazy_static()) } -/// Return an instance of `once_cell::sync::Lazy` or -/// `once_cell::sync::Lazy` that +/// Return an instance of `LazyLock` or +/// `LazyLock` that /// you can use in a public static declaration. /// /// Example: /// /// ``` -/// pub static GLOBAL_REX: Lazy = lazy_regex!("^ab+$"i); +/// pub static GLOBAL_REX: LazyLock = lazy_regex!("^ab+$"i); /// ``` /// /// As for other macros, the regex is checked at compilation time. @@ -83,13 +83,13 @@ pub fn lazy_regex(input: TokenStream) -> TokenStream { process(input, false, |regex_code| regex_code.build) } -/// Return an instance of `once_cell::sync::Lazy` that +/// Return an instance of `LazyLock` that /// you can use in a public static declaration. /// /// Example: /// /// ``` -/// pub static GLOBAL_REX: Lazy = bytes_lazy_regex!("^ab+$"i); +/// pub static GLOBAL_REX: LazyLock = bytes_lazy_regex!("^ab+$"i); /// ``` /// /// As for other macros, the regex is checked at compilation time. diff --git a/src/proc_macros/regex_code.rs b/src/proc_macros/regex_code.rs index e06b02a..69f613b 100644 --- a/src/proc_macros/regex_code.rs +++ b/src/proc_macros/regex_code.rs @@ -61,7 +61,7 @@ impl RegexCode { quote!(RegexBuilder) }; let build = quote! { - lazy_regex::Lazy::new(|| { + std::sync::LazyLock::new(|| { //println!("compiling regex {:?}", #pattern); lazy_regex:: #builder_token ::new(#pattern) .case_insensitive(#case_insensitive) @@ -85,7 +85,7 @@ impl RegexCode { RegexInstance::Bytes(..) => quote!(BytesRegex), }; quote! { - static RE: lazy_regex::Lazy = #build; + static RE: std::sync::LazyLock = #build; } }