Skip to content

Commit

Permalink
fix: bump to validator 0.17
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsavio committed Apr 4, 2024
1 parent 6b462ae commit f2318de
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 21 deletions.
100 changes: 88 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
22 changes: 14 additions & 8 deletions src/domain/subscriber_email.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
use validator::validate_email;
use validator::Validate;

#[derive(Debug)]
pub struct SubscriberEmail(String);
// Assuming you have a struct you wish to validate
#[derive(Debug, Validate)]
pub struct SubscriberEmail {
#[validate(email)]
email: String,
}

impl SubscriberEmail {
pub fn parse(s: String) -> Result<SubscriberEmail, String> {
if validate_email(&s) {
Ok(Self(s))
} else {
Err(format!("{} is not a valid email address.", s))
let potential_email = SubscriberEmail { email: s.clone() };
// Perform the validation
match potential_email.validate() {
Ok(_) => Ok(potential_email),
Err(e) => Err(format!("{} is not a valid email address. Error: {:?}", s, e)),
}
}
}


impl AsRef<str> for SubscriberEmail {
fn as_ref(&self) -> &str {
&self.0
&self.email
}
}

Expand Down

0 comments on commit f2318de

Please sign in to comment.