use super::{Result, Error};
pub(crate) struct EmailAddress {
pub(crate) local_part: String,
pub(crate) domain: String,
}
impl EmailAddress {
pub(crate) fn from<S: AsRef<str>>(email_address: S) -> Result<Self> {
let email_address = email_address.as_ref();
let v: Vec<&str> = email_address.split('@').collect();
if v.len() != 2 {
return Err(Error::MalformedEmail(email_address.into()).into())
};
let email = EmailAddress {
local_part: v[0].to_string(),
domain: v[1].to_lowercase()
};
Ok(email)
}
}