Add a MessagePayload trait, and implement it for Body and ChatState.

This commit is contained in:
Emmanuel Gil Peyrot 2017-04-19 23:21:53 +01:00
commit 6a0724d133
2 changed files with 18 additions and 0 deletions

View file

@ -12,3 +12,18 @@ pub mod jingle;
pub mod ping;
pub mod chatstates;
pub mod ibb;
use std::fmt::Debug;
use minidom::Element;
pub trait MessagePayload: Debug {}
pub fn parse_message_payload(elem: &Element) -> Option<Box<MessagePayload>> {
if let Ok(body) = body::parse_body(elem) {
Some(Box::new(body))
} else if let Ok(chatstate) = chatstates::parse_chatstate(elem) {
Some(Box::new(chatstate))
} else {
None
}
}