Skip to content

Commit

Permalink
add FromStr method for EmailAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
techhazard committed May 28, 2023
1 parent 8e2159f commit 0b85d56
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions rust-lib/src/email_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extern crate pest_derive;
use pest::{iterators::Pairs, Parser};
use std::fmt;
use std::hash::Hash;
use std::str::FromStr;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;

Expand Down Expand Up @@ -33,6 +34,18 @@ impl Default for ParsingOptions {
}
}

impl FromStr for EmailAddress {
type Err = fmt::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
if let Some(email) = EmailAddress::parse(s, None) {
Ok(email)
} else {
Err(fmt::Error)
}
}
}

#[derive(Parser)]
#[grammar = "rfc5322.pest"]
struct RFC5322;
Expand Down

0 comments on commit 0b85d56

Please sign in to comment.