chore: update validator to 0.17
This commit is contained in:
parent
9a31080707
commit
1bc7ae4c7a
3 changed files with 26 additions and 9 deletions
20
Cargo.lock
generated
20
Cargo.lock
generated
|
|
@ -1012,6 +1012,16 @@ dependencies = [
|
|||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6"
|
||||
dependencies = [
|
||||
"unicode-bidi",
|
||||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.9.3"
|
||||
|
|
@ -2719,7 +2729,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb"
|
||||
dependencies = [
|
||||
"form_urlencoded",
|
||||
"idna",
|
||||
"idna 0.4.0",
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
|
|
@ -2741,12 +2751,12 @@ 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",
|
||||
"lazy_static",
|
||||
"idna 0.5.0",
|
||||
"once_cell",
|
||||
"regex",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ tracing-log = "0.2"
|
|||
secrecy = { version = "0.8", features = ["serde"] }
|
||||
unicode-segmentation = "1"
|
||||
strum_macros = "0.26"
|
||||
validator = "0.16"
|
||||
validator = "0.17"
|
||||
|
||||
[dependencies.sqlx]
|
||||
version = "0.7"
|
||||
|
|
|
|||
|
|
@ -1,18 +1,25 @@
|
|||
use validator::validate_email;
|
||||
use validator::ValidateEmail;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SubscriberEmail(String);
|
||||
|
||||
impl SubscriberEmail {
|
||||
pub fn parse(s: String) -> Result<SubscriberEmail, String> {
|
||||
if validate_email(&s) {
|
||||
Ok(Self(s))
|
||||
let result = Self(s.clone());
|
||||
if result.validate_email() {
|
||||
Ok(result)
|
||||
} else {
|
||||
Err(format!("{} is not a valid subscriber email.", s))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ValidateEmail for SubscriberEmail {
|
||||
fn as_email_string(&self) -> Option<std::borrow::Cow<str>> {
|
||||
Some(self.0.as_str().into())
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<str> for SubscriberEmail {
|
||||
fn as_ref(&self) -> &str {
|
||||
&self.0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue