diff --git a/README.md b/README.md index 1e71853..4a2575b 100644 --- a/README.md +++ b/README.md @@ -283,7 +283,7 @@ The `ListErrorBuilder::push` and `ListErrorBuilder::insert` methods will ignore | `pattern` | Validation using regular expressions via the `regex` crate | [`regex`](https://crates.io/crates/regex), [`once_cell`](https://crates.io/crates/once_cell) | | `credit-card` | Validation of credit card numbers via the `card-validate` crate | [`card-validate`](https://crates.io/crates/card-validate) | | `phone-number` | Validation of phone numbers via the `phonenumber` crate | [`phonenumber`](https://crates.io/crates/phonenumber) | -| `regex-lite` | Adds support for the `regex-lite` crate for the pattern validator | [`regex-lite`](https://crates.io/crates/regex-lite) | +| `regex-lite` | Adds support for the `regex-lite` crate for the pattern validator and switches the email validator to use `regex-lite` instead of `regex` | [`regex-lite`](https://crates.io/crates/regex-lite) | Additional notes: - Enabling the `regex-lite` feature does not remove the dependency on the `regex` crate, but if you avoid using `#[garde(pattern(...)]` with a string literal, then `regex` will not be used and may be removed by link-time optimisation. diff --git a/garde/src/lib.rs b/garde/src/lib.rs index 5257bdd..3a6e969 100644 --- a/garde/src/lib.rs +++ b/garde/src/lib.rs @@ -281,7 +281,7 @@ //! | `pattern` | Validation using regular expressions via the `regex` crate | [`regex`](https://crates.io/crates/regex), [`once_cell`](https://crates.io/crates/once_cell) | //! | `credit-card` | Validation of credit card numbers via the `card-validate` crate | [`card-validate`](https://crates.io/crates/card-validate) | //! | `phone-number` | Validation of phone numbers via the `phonenumber` crate | [`phonenumber`](https://crates.io/crates/phonenumber) | -//! | `regex-lite` | Adds support for the `regex-lite` crate for the pattern validator | [`regex-lite`](https://crates.io/crates/regex-lite) | +//! | `regex-lite` | Adds support for the `regex-lite` crate for the pattern validator and switches the email validator to use `regex-lite` instead of `regex` | [`regex-lite`](https://crates.io/crates/regex-lite) | pub mod error; pub mod rules; diff --git a/garde/src/rules/email.rs b/garde/src/rules/email.rs index 9f95a44..1632a10 100644 --- a/garde/src/rules/email.rs +++ b/garde/src/rules/email.rs @@ -16,7 +16,10 @@ use std::fmt::Display; use std::str::FromStr; use once_cell::sync::Lazy; +#[cfg(not(feature = "regex-lite"))] use regex::Regex; +#[cfg(feature = "regex-lite")] +use regex_lite::Regex; use super::AsStr; use crate::error::Error;