Remove the MessagePayload trait, it was a bad idea.

This commit is contained in:
Emmanuel Gil Peyrot 2017-04-20 00:14:47 +01:00
parent b8b0494c19
commit a9993b1281
3 changed files with 8 additions and 11 deletions

View file

@ -1,7 +1,6 @@
use minidom::Element;
use error::Error;
use super::MessagePayload;
// TODO: also support components and servers.
use ns::JABBER_CLIENT_NS;
@ -11,8 +10,6 @@ pub struct Body {
body: String,
}
impl MessagePayload for Body {}
pub fn parse_body(root: &Element) -> Result<Body, Error> {
if !root.is("body", JABBER_CLIENT_NS) {
return Err(Error::ParseError("This is not a body element."));

View file

@ -1,7 +1,6 @@
use minidom::Element;
use error::Error;
use super::MessagePayload;
use ns::CHATSTATES_NS;
@ -14,8 +13,6 @@ pub enum ChatState {
Paused,
}
impl MessagePayload for ChatState {}
pub fn parse_chatstate(root: &Element) -> Result<ChatState, Error> {
for _ in root.children() {
return Err(Error::ParseError("Unknown child in chatstate element."));

View file

@ -13,16 +13,19 @@ pub mod ping;
pub mod chatstates;
pub mod ibb;
use std::fmt::Debug;
use minidom::Element;
pub trait MessagePayload: Debug {}
#[derive(Debug)]
pub enum MessagePayload {
Body(body::Body),
ChatState(chatstates::ChatState),
}
pub fn parse_message_payload(elem: &Element) -> Option<Box<MessagePayload>> {
pub fn parse_message_payload(elem: &Element) -> Option<MessagePayload> {
if let Ok(body) = body::parse_body(elem) {
Some(Box::new(body))
Some(MessagePayload::Body(body))
} else if let Ok(chatstate) = chatstates::parse_chatstate(elem) {
Some(Box::new(chatstate))
Some(MessagePayload::ChatState(chatstate))
} else {
None
}