unify Client::Event and Component::Event into Event

This commit is contained in:
Astro 2017-07-23 02:46:47 +02:00
commit 993fdcab8f
5 changed files with 14 additions and 52 deletions

38
src/event.rs Normal file
View file

@ -0,0 +1,38 @@
use minidom::Element;
#[derive(Debug)]
pub enum Event {
Online,
Disconnected,
Stanza(Element),
}
impl Event {
pub fn is_online(&self) -> bool {
match *self {
Event::Online => true,
_ => false,
}
}
pub fn is_stanza(&self, name: &str) -> bool {
match *self {
Event::Stanza(ref stanza) => stanza.name() == name,
_ => false,
}
}
pub fn as_stanza(&self) -> Option<&Element> {
match *self {
Event::Stanza(ref stanza) => Some(stanza),
_ => None,
}
}
pub fn into_stanza(self) -> Option<Element> {
match self {
Event::Stanza(stanza) => Some(stanza),
_ => None,
}
}
}