Skip to content

Commit 51a7818

Browse files
committed
fix: bump to validator 0.17
1 parent 6b462ae commit 51a7818

File tree

3 files changed

+101
-21
lines changed

3 files changed

+101
-21
lines changed

Cargo.lock

Lines changed: 88 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ tracing-subscriber = { version = "0.3", features = ["registry", "env-filter"] }
2626
tracing-bunyan-formatter = "0.3"
2727
serde-aux = "4.5"
2828
unicode-segmentation = "1.11"
29-
validator = "0.16.0"
29+
validator = { version = "0.17", features = ["derive"] }
3030
rand = { version = "0.8", features = ["std_rng"] }
3131

3232
[dependencies.reqwest]

src/domain/subscriber_email.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
use validator::validate_email;
1+
use validator::Validate;
22

3-
#[derive(Debug)]
4-
pub struct SubscriberEmail(String);
3+
#[derive(Debug, Validate)]
4+
pub struct SubscriberEmail {
5+
#[validate(email)]
6+
email: String,
7+
}
58

69
impl SubscriberEmail {
710
pub fn parse(s: String) -> Result<SubscriberEmail, String> {
8-
if validate_email(&s) {
9-
Ok(Self(s))
10-
} else {
11-
Err(format!("{} is not a valid email address.", s))
11+
let potential_email = SubscriberEmail { email: s.clone() };
12+
match potential_email.validate() {
13+
Ok(_) => Ok(potential_email),
14+
Err(e) => Err(format!("{} is not a valid email address. Error: {:?}", s, e)),
1215
}
1316
}
1417
}
1518

19+
1620
impl AsRef<str> for SubscriberEmail {
1721
fn as_ref(&self) -> &str {
18-
&self.0
22+
&self.email
1923
}
2024
}
2125

0 commit comments

Comments
 (0)