Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use std::sync::LazyLock instead of once_cell::sync::Lazy #38

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion examples/regexes/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use lazy_regex::*;

pub static SHARED: Lazy<Regex> = lazy_regex!("^test$");
pub static SHARED: LazyLock<Regex> = lazy_regex!("^test$");

fn example_builds() {
// build a simple regex
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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<Regex> = lazy_regex!("^ab+$"i);
pub static GLOBAL_REX: LazyLock<Regex> = lazy_regex!("^ab+$"i);
```

Like for the other macros, the regex is static, checked at compile time, and lazily built at first use.
Expand Down Expand Up @@ -225,7 +225,7 @@ pub use {
bytes_regex_replace_all,
bytes_regex_switch,
},
once_cell::sync::Lazy,
std::sync::LazyLock
};

#[cfg(not(feature = "lite"))]
Expand Down
10 changes: 5 additions & 5 deletions src/proc_macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<regex::Regex>` or
/// `once_cell::sync::Lazy<regex::bytes::Regex>` that
/// Return an instance of `LazyLock<regex::Regex>` or
/// `LazyLock<regex::bytes::Regex>` that
/// you can use in a public static declaration.
///
/// Example:
///
/// ```
/// pub static GLOBAL_REX: Lazy<Regex> = lazy_regex!("^ab+$"i);
/// pub static GLOBAL_REX: LazyLock<Regex> = lazy_regex!("^ab+$"i);
/// ```
///
/// As for other macros, the regex is checked at compilation time.
Expand All @@ -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<bytes::Regex>` that
/// Return an instance of `LazyLock<bytes::Regex>` that
/// you can use in a public static declaration.
///
/// Example:
///
/// ```
/// pub static GLOBAL_REX: Lazy<bytes::Regex> = bytes_lazy_regex!("^ab+$"i);
/// pub static GLOBAL_REX: LazyLock<bytes::Regex> = bytes_lazy_regex!("^ab+$"i);
/// ```
///
/// As for other macros, the regex is checked at compilation time.
Expand Down
4 changes: 2 additions & 2 deletions src/proc_macros/regex_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -85,7 +85,7 @@ impl RegexCode {
RegexInstance::Bytes(..) => quote!(BytesRegex),
};
quote! {
static RE: lazy_regex::Lazy<lazy_regex:: #regex_token > = #build;
static RE: std::sync::LazyLock<lazy_regex:: #regex_token > = #build;
}
}

Expand Down