This commit is contained in:
Astro 2018-08-02 19:58:19 +02:00
commit b929a3c71e
7 changed files with 57 additions and 3 deletions

View file

@ -1,13 +1,18 @@
use minidom::Element;
/// High-level event on the Stream implemented by Client and Component
#[derive(Debug)]
pub enum Event {
/// Stream is connected and initialized
Online,
/// Stream end
Disconnected,
/// Received stanza/nonza
Stanza(Element),
}
impl Event {
/// `Online` event?
pub fn is_online(&self) -> bool {
match *self {
Event::Online => true,
@ -15,6 +20,7 @@ impl Event {
}
}
/// `Stanza` event?
pub fn is_stanza(&self, name: &str) -> bool {
match *self {
Event::Stanza(ref stanza) => stanza.name() == name,
@ -22,6 +28,7 @@ impl Event {
}
}
/// If this is a `Stanza` event, get its data
pub fn as_stanza(&self) -> Option<&Element> {
match *self {
Event::Stanza(ref stanza) => Some(stanza),
@ -29,6 +36,7 @@ impl Event {
}
}
/// If this is a `Stanza` event, unwrap into its data
pub fn into_stanza(self) -> Option<Element> {
match self {
Event::Stanza(stanza) => Some(stanza),