Skip to content

Commit 70bc7cc

Browse files
atezetgreyblake
authored andcommitted
Replace lazy_static as a dependency with LazyLock when using regex
1 parent ae0699a commit 70bc7cc

File tree

6 files changed

+8
-12
lines changed

6 files changed

+8
-12
lines changed

Cargo.lock

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ At the moment the string inner type supports only `String` (owned) type.
101101

102102
Requirements:
103103
* `regex` feature of `nutype` is enabled.
104-
* You have to explicitly include `regex` and `lazy_static` as dependencies.
104+
* You have to explicitly include `regex` as a dependency.
105105

106106
There are a number of ways you can use regex.
107107

@@ -354,7 +354,7 @@ assert_eq!(name.into_inner(), " boo ");
354354

355355
* `arbitrary` - enables derive of [`arbitrary::Arbitrary`](https://docs.rs/arbitrary/latest/arbitrary/trait.Arbitrary.html).
356356
* `new_unchecked` - enables generation of unsafe `::new_unchecked()` function.
357-
* `regex` - allows to use `regex = ` validation on string-based types. Note: your crate also has to explicitly have `regex` and `lazy_static` within dependencies.
357+
* `regex` - allows to use `regex = ` validation on string-based types. Note: your crate also has to explicitly have `regex` within its dependencies.
358358
* `serde` - integrations with [`serde`](https://crates.io/crates/serde) crate. Allows to derive `Serialize` and `Deserialize` traits.
359359
* `schemars08` - allows to derive [`JsonSchema`](https://docs.rs/schemars/0.8.12/schemars/trait.JsonSchema.html) trait of [schemars](https://crates.io/crates/schemars) crate. Note that at the moment validation rules are not respected.
360360
* `std` - enabled by default. Use `default-features = false` to disable.

dummy/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ serde_json = "*"
1212
schemars = "*"
1313
regex = "*"
1414
once_cell = "*"
15-
lazy_static = "*"
1615
ron = "0.8.1"
1716
arbitrary = "1.3.2"
1817
num = "0.4.3"

nutype/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
//!
115115
//! Requirements:
116116
//! * `regex` feature of `nutype` is enabled.
117-
//! * You crate have to explicitly include `regex` and `lazy_static` dependencies.
117+
//! * You crate have to explicitly include `regex` as a dependency.
118118
//!
119119
//! There are a number of ways you can use regex.
120120
//!
@@ -406,7 +406,7 @@
406406
//!
407407
//! * `arbitrary` - enables derive of [`arbitrary::Arbitrary`](https://docs.rs/arbitrary/latest/arbitrary/trait.Arbitrary.html).
408408
//! * `new_unchecked` - enables generation of unsafe `::new_unchecked()` function.
409-
//! * `regex` - allows to use `regex = ` validation on string-based types. Note: your crate also has to explicitly have `regex` and `lazy_static` within dependencies.
409+
//! * `regex` - allows to use `regex = ` validation on string-based types. Note: your crate also has to explicitly have `regex` within its dependencies.
410410
//! * `serde` - integrations with [`serde`](https://crates.io/crates/serde) crate. Allows to derive `Serialize` and `Deserialize` traits.
411411
//! * `schemars08` - allows to derive [`JsonSchema`](https://docs.rs/schemars/0.8.12/schemars/trait.JsonSchema.html) trait of [schemars](https://crates.io/crates/schemars) crate. Note that at the moment validation rules are not respected.
412412
//! * `std` - enabled by default. Use `default-features = false` to disable.

nutype_macros/src/string/gen/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,9 @@ impl GenerateNewtype for StringNewtype {
125125
match regex_def {
126126
RegexDef::StringLiteral(regex_str_lit) => {
127127
quote!(
128-
lazy_static::lazy_static! {
129-
// Make up a sufficiently unique regex name to ensure that it does
130-
// not clashes with anything import with `use super::*`.
131-
static ref __NUTYPE_REGEX__: ::regex::Regex = ::regex::Regex::new(#regex_str_lit).expect("Nutype failed to a build a regex");
132-
}
128+
// Make up a sufficiently unique regex name to ensure that it does
129+
// not clashes with anything import with `use super::*`.
130+
static __NUTYPE_REGEX__: ::std::sync::LazyLock<::regex::Regex> = ::std::sync::LazyLock::new(|| ::regex::Regex::new(#regex_str_lit).expect("Nutype failed to a build a regex"));
133131
if !__NUTYPE_REGEX__.is_match(&val) {
134132
return Err(#error_type_name::RegexViolated);
135133
}

nutype_macros/src/string/parse.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl Parse for SpannedStringValidator {
131131
} else {
132132
let msg = concat!(
133133
"To validate string types with regex, the feature `regex` of the crate `nutype` must be enabled.\n",
134-
"IMPORTANT: Make sure that your crate EXPLICITLY depends on `regex` and `lazy_static` crates.\n",
134+
"IMPORTANT: Make sure that your crate EXPLICITLY depends on the `regex` crate.\n",
135135
"And... don't forget to take care of yourself and your beloved ones. That is even more important.",
136136
);
137137
Err(syn::Error::new(ident.span(), msg))

0 commit comments

Comments
 (0)