From 332cb3c63331dd0f03ebbea025581d6d2d73921f Mon Sep 17 00:00:00 2001 From: alexsavio Date: Thu, 4 Apr 2024 09:34:25 +0200 Subject: [PATCH] fix: bump to validator 0.17 --- Cargo.lock | 100 +++++++++++++++++++++++++++++---- Cargo.toml | 2 +- src/domain/subscriber_email.rs | 22 +++++--- 3 files changed, 103 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e686536..5057b74 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -568,6 +568,41 @@ dependencies = [ "typenum", ] +[[package]] +name = "darling" +version = "0.20.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc5d6b04b3fd0ba9926f945895de7d806260a2d7431ba82e7edaecb043c4c6b8" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04e48a959bcd5c761246f5d090ebc2fbf7b9cd527a492b07a67510c108f1e7e3" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.58", +] + +[[package]] +name = "darling_macro" +version = "0.20.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1545d67a2149e1d93b7e5c7752dce5a7426eb5d1357ddcfd89336b94444f77" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.58", +] + [[package]] name = "deadpool" version = "0.10.0" @@ -1158,14 +1193,10 @@ dependencies = [ ] [[package]] -name = "idna" -version = "0.4.0" +name = "ident_case" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idna" @@ -1673,6 +1704,30 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro2" version = "1.0.79" @@ -2411,6 +2466,12 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "subtle" version = "2.5.0" @@ -2838,7 +2899,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" dependencies = [ "form_urlencoded", - "idna 0.5.0", + "idna", "percent-encoding", ] @@ -2859,17 +2920,32 @@ dependencies = [ [[package]] name = "validator" -version = "0.16.1" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b92f40481c04ff1f4f61f304d61793c7b56ff76ac1469f1beb199b1445b253bd" +checksum = "da339118f018cc70ebf01fafc103360528aad53717e4bf311db929cb01cb9345" dependencies = [ - "idna 0.4.0", - "lazy_static", + "idna", + "once_cell", "regex", "serde", "serde_derive", "serde_json", "url", + "validator_derive", +] + +[[package]] +name = "validator_derive" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76e88ea23b8f5e59230bff8a2f03c0ee0054a61d5b8343a38946bcd406fe624c" +dependencies = [ + "darling", + "proc-macro-error", + "proc-macro2", + "quote", + "regex", + "syn 2.0.58", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index f4e8b47..d0e7cb8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ tracing-subscriber = { version = "0.3", features = ["registry", "env-filter"] } tracing-bunyan-formatter = "0.3" serde-aux = "4.5" unicode-segmentation = "1.11" -validator = "0.16.0" +validator = { version = "0.17", features = ["derive"] } rand = { version = "0.8", features = ["std_rng"] } [dependencies.reqwest] diff --git a/src/domain/subscriber_email.rs b/src/domain/subscriber_email.rs index f66f18e..538b122 100644 --- a/src/domain/subscriber_email.rs +++ b/src/domain/subscriber_email.rs @@ -1,21 +1,27 @@ -use validator::validate_email; +use validator::Validate; -#[derive(Debug)] -pub struct SubscriberEmail(String); +#[derive(Debug, Validate)] +pub struct SubscriberEmail { + #[validate(email)] + email: String, +} impl SubscriberEmail { pub fn parse(s: String) -> Result { - if validate_email(&s) { - Ok(Self(s)) - } else { - Err(format!("{} is not a valid email address.", s)) + let potential_email = SubscriberEmail { email: s.clone() }; + match potential_email.validate() { + Ok(_) => Ok(potential_email), + Err(e) => Err(format!( + "{} is not a valid email address. Error: {:?}", + s, e + )), } } } impl AsRef for SubscriberEmail { fn as_ref(&self) -> &str { - &self.0 + &self.email } }