mirror of
https://github.com/LukeMathWalker/zero-to-production.git
synced 2024-09-27 05:40:00 +00:00
Update validator to 0.17
This commit is contained in:
parent
a48a2a2472
commit
7c2244a489
2 changed files with 11 additions and 4 deletions
|
@ -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"] }
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue