Add a generate_attribute! macro, and use it for the common case.

This commit is contained in:
Emmanuel Gil Peyrot 2017-06-14 00:50:57 +01:00
commit 0f297d2d2d
10 changed files with 158 additions and 499 deletions

View file

@ -15,42 +15,13 @@ use ns;
type Group = String;
#[derive(Debug, Clone, PartialEq)]
pub enum Subscription {
None,
From,
To,
Both,
Remove,
}
impl FromStr for Subscription {
type Err = Error;
fn from_str(s: &str) -> Result<Subscription, Error> {
Ok(match s {
"none" => Subscription::None,
"from" => Subscription::From,
"to" => Subscription::To,
"both" => Subscription::Both,
"remove" => Subscription::Remove,
_ => return Err(Error::ParseError("Unknown value for attribute 'subscription'.")),
})
}
}
impl IntoAttributeValue for Subscription {
fn into_attribute_value(self) -> Option<String> {
Some(String::from(match self {
Subscription::None => "none",
Subscription::From => "from",
Subscription::To => "to",
Subscription::Both => "both",
Subscription::Remove => "remove",
}))
}
}
generate_attribute!(Subscription, "subscription", {
None => "none",
From => "from",
To => "to",
Both => "both",
Remove => "remove",
});
#[derive(Debug, Clone, PartialEq)]
pub struct Item {