Update validator to 0.17

This commit is contained in:
Sandro Eiler 2024-03-05 13:08:44 +01:00
parent a48a2a2472
commit 7c2244a489
2 changed files with 11 additions and 4 deletions

View file

@ -33,7 +33,7 @@ rand = { version = "0.8", features=["std_rng"] }
anyhow = "1.0.40"
base64 = "0.21.0"
argon2 = { version = "0.4", features = ["std"] }
validator = "0.16"
validator = "0.17"
tracing-actix-web = "0.7"
secrecy = { version = "0.8", features = ["serde"] }
actix-web-flash-messages = { version = "0.4", features = ["cookies"] }

View file

@ -1,18 +1,25 @@
use validator::validate_email;
use validator::ValidateEmail;
#[derive(Debug)]
pub struct SubscriberEmail(String);
impl SubscriberEmail {
pub fn parse(s: String) -> Result<SubscriberEmail, String> {
if validate_email(&s) {
Ok(Self(s))
let email = Self(s.clone());
if email.validate_email() {
Ok(email)
} 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