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

@ -14,39 +14,10 @@ use error::Error;
use ns;
#[derive(Debug, Clone, PartialEq)]
pub enum Stanza {
Iq,
Message,
}
impl Default for Stanza {
fn default() -> Stanza {
Stanza::Iq
}
}
impl FromStr for Stanza {
type Err = Error;
fn from_str(s: &str) -> Result<Stanza, Error> {
Ok(match s {
"iq" => Stanza::Iq,
"message" => Stanza::Message,
_ => return Err(Error::ParseError("Invalid 'stanza' attribute.")),
})
}
}
impl IntoAttributeValue for Stanza {
fn into_attribute_value(self) -> Option<String> {
match self {
Stanza::Iq => None,
Stanza::Message => Some(String::from("message")),
}
}
}
generate_attribute!(Stanza, "stanza", {
Iq => "iq",
Message => "message",
}, Default = Iq);
#[derive(Debug, Clone)]
pub enum IBB {