more of a ClientEvent api
This commit is contained in:
parent
e2a4f609fb
commit
7f667041d9
3 changed files with 52 additions and 29 deletions
31
src/client/event.rs
Normal file
31
src/client/event.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
use xml;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Event {
|
||||
Online,
|
||||
Disconnected,
|
||||
Stanza(xml::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<&xml::Element> {
|
||||
match self {
|
||||
&Event::Stanza(ref stanza) => Some(stanza),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -19,6 +19,8 @@ mod auth;
|
|||
use self::auth::*;
|
||||
mod bind;
|
||||
use self::bind::*;
|
||||
mod event;
|
||||
pub use self::event::Event as ClientEvent;
|
||||
|
||||
pub struct Client {
|
||||
pub jid: Jid,
|
||||
|
|
@ -99,13 +101,6 @@ impl Client {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ClientEvent {
|
||||
Online,
|
||||
Disconnected,
|
||||
Stanza(xml::Element),
|
||||
}
|
||||
|
||||
impl Stream for Client {
|
||||
type Item = ClientEvent;
|
||||
type Error = String;
|
||||
|
|
|
|||
Loading…
Reference in a new issue