Add a generate_attribute! macro, and use it for the common case.
This commit is contained in:
parent
9955c1131b
commit
0f297d2d2d
10 changed files with 158 additions and 499 deletions
|
|
@ -102,14 +102,13 @@ impl Into<Element> for MessagePayload {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum MessageType {
|
||||
Chat,
|
||||
Error,
|
||||
Groupchat,
|
||||
Headline,
|
||||
Normal,
|
||||
}
|
||||
generate_attribute!(MessageType, "type", {
|
||||
Chat => "chat",
|
||||
Error => "error",
|
||||
Groupchat => "groupchat",
|
||||
Headline => "headline",
|
||||
Normal => "normal",
|
||||
});
|
||||
|
||||
impl Default for MessageType {
|
||||
fn default() -> MessageType {
|
||||
|
|
@ -117,34 +116,6 @@ impl Default for MessageType {
|
|||
}
|
||||
}
|
||||
|
||||
impl FromStr for MessageType {
|
||||
type Err = Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<MessageType, Error> {
|
||||
Ok(match s {
|
||||
"chat" => MessageType::Chat,
|
||||
"error" => MessageType::Error,
|
||||
"groupchat" => MessageType::Groupchat,
|
||||
"headline" => MessageType::Headline,
|
||||
"normal" => MessageType::Normal,
|
||||
|
||||
_ => return Err(Error::ParseError("Invalid 'type' attribute on message element.")),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoAttributeValue for MessageType {
|
||||
fn into_attribute_value(self) -> Option<String> {
|
||||
Some(match self {
|
||||
MessageType::Chat => "chat",
|
||||
MessageType::Error => "error",
|
||||
MessageType::Groupchat => "groupchat",
|
||||
MessageType::Headline => "headline",
|
||||
MessageType::Normal => "normal",
|
||||
}.to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
type Lang = String;
|
||||
type Body = String;
|
||||
type Subject = String;
|
||||
|
|
|
|||
Loading…
Reference in a new issue