Skip to content

Commit

Permalink
use regex-lite in email validator if regex-lite feature is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
jirutka committed Jul 29, 2023
1 parent 401d751 commit 6313e7f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion garde/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions garde/src/rules/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6313e7f

Please sign in to comment.