use std::fmt;
#[derive(Debug, PartialEq)]
pub struct FN<'a> {
pub name: &'a str,
}
impl<'a> FN<'a> {
pub fn new(raw: &'a str) -> FN<'a> {
let splits: Vec<&str> = raw.split(':').collect();
FN { name: splits[1] }
}
}
impl<'a> fmt::Display for FN<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.name)
}
}
#[derive(Debug, PartialEq)]
pub enum EMailType {
Home,
Work,
Other,
}
#[derive(Debug, PartialEq)]
pub struct EMail<'a> {
pub addr: &'a str,
pub r#type: EMailType,
pub pref: bool,
}
impl<'a> EMail<'a> {
pub fn new(raw: &'a str) -> EMail {
let splits: Vec<&str> = raw.split(":").collect();
let (prefix, addr) = match splits.as_slice() {
[prefix, addr] => (prefix, addr),
_ => unreachable!(),
};
let mut r#type = EMailType::Other;
let lower = prefix.to_lowercase();
if lower.find("type").is_some() {
if lower.contains("work") {
r#type = EMailType::Work;
} else if lower.contains("home") {
r#type = EMailType::Home;
}
}
let pref = false;
EMail { addr, r#type, pref }
}
fn parse(&self) -> String {
self.addr.to_string()
}
}
impl<'a> fmt::Display for EMail<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.parse())
}
}