Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Remove lazy static #164

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ At the moment the string inner type supports only `String` (owned) type.

Requirements:
* `regex` feature of `nutype` is enabled.
* You have to explicitly include `regex` and `lazy_static` as dependencies.
* You have to explicitly include `regex` as a dependency.

There are a number of ways you can use regex.

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

* `arbitrary` - enables derive of [`arbitrary::Arbitrary`](https://docs.rs/arbitrary/latest/arbitrary/trait.Arbitrary.html).
* `new_unchecked` - enables generation of unsafe `::new_unchecked()` function.
* `regex` - allows to use `regex = ` validation on string-based types. Note: your crate also has to explicitly have `regex` and `lazy_static` within dependencies.
* `regex` - allows to use `regex = ` validation on string-based types. Note: your crate also has to explicitly have `regex` within its dependencies.
* `serde` - integrations with [`serde`](https://crates.io/crates/serde) crate. Allows to derive `Serialize` and `Deserialize` traits.
* `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.
* `std` - enabled by default. Use `default-features = false` to disable.
Expand Down
1 change: 0 additions & 1 deletion dummy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ serde_json = "*"
schemars = "*"
regex = "*"
once_cell = "*"
lazy_static = "*"
ron = "0.8.1"
arbitrary = "1.3.2"
num = "0.4.3"
4 changes: 2 additions & 2 deletions nutype/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
//!
//! Requirements:
//! * `regex` feature of `nutype` is enabled.
//! * You crate have to explicitly include `regex` and `lazy_static` dependencies.
//! * You crate have to explicitly include `regex` as a dependency.
//!
//! There are a number of ways you can use regex.
//!
Expand Down Expand Up @@ -406,7 +406,7 @@
//!
//! * `arbitrary` - enables derive of [`arbitrary::Arbitrary`](https://docs.rs/arbitrary/latest/arbitrary/trait.Arbitrary.html).
//! * `new_unchecked` - enables generation of unsafe `::new_unchecked()` function.
//! * `regex` - allows to use `regex = ` validation on string-based types. Note: your crate also has to explicitly have `regex` and `lazy_static` within dependencies.
//! * `regex` - allows to use `regex = ` validation on string-based types. Note: your crate also has to explicitly have `regex` within its dependencies.
//! * `serde` - integrations with [`serde`](https://crates.io/crates/serde) crate. Allows to derive `Serialize` and `Deserialize` traits.
//! * `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.
//! * `std` - enabled by default. Use `default-features = false` to disable.
Expand Down
8 changes: 3 additions & 5 deletions nutype_macros/src/string/gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,9 @@ impl GenerateNewtype for StringNewtype {
match regex_def {
RegexDef::StringLiteral(regex_str_lit) => {
quote!(
lazy_static::lazy_static! {
// Make up a sufficiently unique regex name to ensure that it does
// not clashes with anything import with `use super::*`.
static ref __NUTYPE_REGEX__: ::regex::Regex = ::regex::Regex::new(#regex_str_lit).expect("Nutype failed to a build a regex");
}
// Make up a sufficiently unique regex name to ensure that it does
// not clashes with anything import with `use super::*`.
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"));
if !__NUTYPE_REGEX__.is_match(&val) {
return Err(#error_name::RegexViolated);
}
Expand Down
2 changes: 1 addition & 1 deletion nutype_macros/src/string/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl Parse for SpannedStringValidator {
} else {
let msg = concat!(
"To validate string types with regex, the feature `regex` of the crate `nutype` must be enabled.\n",
"IMPORTANT: Make sure that your crate EXPLICITLY depends on `regex` and `lazy_static` crates.\n",
"IMPORTANT: Make sure that your crate EXPLICITLY depends on the `regex` crate.\n",
"And... don't forget to take care of yourself and your beloved ones. That is even more important.",
);
Err(syn::Error::new(ident.span(), msg))
Expand Down
Loading