Skip to content

Commit

Permalink
Use std::sync::OnceLock in generated code and remove once_cell depend…
Browse files Browse the repository at this point in the history
…ency.
  • Loading branch information
frozenlib committed Dec 1, 2023
1 parent a155e9a commit c37e3e3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
5 changes: 2 additions & 3 deletions parse-display-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
3 changes: 1 addition & 2 deletions parse-display/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
1 change: 0 additions & 1 deletion parse-display/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,6 @@ mod tests;

#[cfg(feature = "std")]
pub mod helpers {
pub use once_cell;
pub use regex;
}

Expand Down

0 comments on commit c37e3e3

Please sign in to comment.