-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b85d56
commit 322225e
Showing
1 changed file
with
17 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,11 +34,27 @@ impl Default for ParsingOptions { | |
} | ||
} | ||
|
||
/// Allows conversion from string slices (&str) to EmailAddress using the FromStr trait. | ||
/// This wraps around `EmailAddress::parse` using the default `ParsingOptions`. | ||
/// | ||
/// # Examples | ||
/// ``` | ||
/// use email_address_parser::EmailAddress; | ||
/// use std::str::FromStr; | ||
/// | ||
/// const input_address : &str = "[email protected]"; | ||
/// | ||
/// let myaddr : EmailAddress = input_address.parse().expect("could not parse str into EmailAddress"); | ||
/// let myotheraddr = EmailAddress::from_str(input_address).expect("could create EmailAddress from str"); | ||
/// | ||
/// assert_eq!(myaddr, myotheraddr); | ||
/// ``` | ||
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) { | ||
let opts = ParsingOptions::default(); | ||
if let Some(email) = EmailAddress::parse(s, Some(opts)) { | ||
Ok(email) | ||
} else { | ||
Err(fmt::Error) | ||
|