2017-07-17 18:53:00 +00:00
|
|
|
use minidom::Element;
|
2017-07-12 23:47:05 +00:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Event {
|
|
|
|
Online,
|
|
|
|
Disconnected,
|
2017-07-17 18:53:00 +00:00
|
|
|
Stanza(Element),
|
2017-07-12 23:47:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Event {
|
|
|
|
pub fn is_online(&self) -> bool {
|
|
|
|
match self {
|
|
|
|
&Event::Online => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_stanza(&self, name: &str) -> bool {
|
|
|
|
match self {
|
2017-07-17 18:53:00 +00:00
|
|
|
&Event::Stanza(ref stanza) => stanza.name() == name,
|
2017-07-12 23:47:05 +00:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-17 18:53:00 +00:00
|
|
|
pub fn as_stanza(&self) -> Option<&Element> {
|
2017-07-12 23:47:05 +00:00
|
|
|
match self {
|
|
|
|
&Event::Stanza(ref stanza) => Some(stanza),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
2017-07-19 23:07:07 +00:00
|
|
|
|
|
|
|
pub fn into_stanza(self) -> Option<Element> {
|
|
|
|
match self {
|
|
|
|
Event::Stanza(stanza) => Some(stanza),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
2017-07-12 23:47:05 +00:00
|
|
|
}
|