From 993fdcab8f85e14f999871da85c0c975402b6c37 Mon Sep 17 00:00:00 2001 From: Astro Date: Sun, 23 Jul 2017 02:46:47 +0200 Subject: [PATCH] unify Client::Event and Component::Event into Event --- src/client/mod.rs | 11 +++++------ src/component/event.rs | 38 -------------------------------------- src/component/mod.rs | 11 +++++------ src/{client => }/event.rs | 0 src/lib.rs | 6 ++++-- 5 files changed, 14 insertions(+), 52 deletions(-) delete mode 100644 src/component/event.rs rename src/{client => }/event.rs (100%) diff --git a/src/client/mod.rs b/src/client/mod.rs index 77641110..e814f9b6 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -15,13 +15,12 @@ use super::xmpp_codec::Packet; use super::xmpp_stream; use super::starttls::{NS_XMPP_TLS, StartTlsClient}; use super::happy_eyeballs::Connecter; +use super::event::Event; mod auth; use self::auth::ClientAuth; mod bind; use self::bind::ClientBind; -mod event; -pub use self::event::Event as ClientEvent; pub struct Client { pub jid: Jid, @@ -112,7 +111,7 @@ impl Client { } impl Stream for Client { - type Item = ClientEvent; + type Item = Event; type Error = String; fn poll(&mut self) -> Poll, Self::Error> { @@ -127,7 +126,7 @@ impl Stream for Client { match connect.poll() { Ok(Async::Ready(stream)) => { self.state = ClientState::Connected(stream); - Ok(Async::Ready(Some(ClientEvent::Online))) + Ok(Async::Ready(Some(Event::Online))) }, Ok(Async::NotReady) => { self.state = ClientState::Connecting(connect); @@ -142,11 +141,11 @@ impl Stream for Client { Ok(Async::Ready(None)) => { // EOF self.state = ClientState::Disconnected; - Ok(Async::Ready(Some(ClientEvent::Disconnected))) + Ok(Async::Ready(Some(Event::Disconnected))) }, Ok(Async::Ready(Some(Packet::Stanza(stanza)))) => { self.state = ClientState::Connected(stream); - Ok(Async::Ready(Some(ClientEvent::Stanza(stanza)))) + Ok(Async::Ready(Some(Event::Stanza(stanza)))) }, Ok(Async::NotReady) | Ok(Async::Ready(_)) => { diff --git a/src/component/event.rs b/src/component/event.rs deleted file mode 100644 index 8ff44bd7..00000000 --- a/src/component/event.rs +++ /dev/null @@ -1,38 +0,0 @@ -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 { - match self { - Event::Stanza(stanza) => Some(stanza), - _ => None, - } - } -} diff --git a/src/component/mod.rs b/src/component/mod.rs index 95790f00..2964700f 100644 --- a/src/component/mod.rs +++ b/src/component/mod.rs @@ -11,11 +11,10 @@ use jid::{Jid, JidParseError}; use super::xmpp_codec::Packet; use super::xmpp_stream; use super::happy_eyeballs::Connecter; +use super::event::Event; mod auth; use self::auth::ComponentAuth; -mod event; -pub use self::event::Event as ComponentEvent; pub struct Component { pub jid: Jid, @@ -67,7 +66,7 @@ impl Component { } impl Stream for Component { - type Item = ComponentEvent; + type Item = Event; type Error = String; fn poll(&mut self) -> Poll, Self::Error> { @@ -82,7 +81,7 @@ impl Stream for Component { match connect.poll() { Ok(Async::Ready(stream)) => { self.state = ComponentState::Connected(stream); - Ok(Async::Ready(Some(ComponentEvent::Online))) + Ok(Async::Ready(Some(Event::Online))) }, Ok(Async::NotReady) => { self.state = ComponentState::Connecting(connect); @@ -101,11 +100,11 @@ impl Stream for Component { Ok(Async::Ready(None)) => { // EOF self.state = ComponentState::Disconnected; - Ok(Async::Ready(Some(ComponentEvent::Disconnected))) + Ok(Async::Ready(Some(Event::Disconnected))) }, Ok(Async::Ready(Some(Packet::Stanza(stanza)))) => { self.state = ComponentState::Connected(stream); - Ok(Async::Ready(Some(ComponentEvent::Stanza(stanza)))) + Ok(Async::Ready(Some(Event::Stanza(stanza)))) }, Ok(Async::Ready(_)) => { self.state = ComponentState::Connected(stream); diff --git a/src/client/event.rs b/src/event.rs similarity index 100% rename from src/client/event.rs rename to src/event.rs diff --git a/src/lib.rs b/src/lib.rs index 81f3b1c6..ddb4f9a3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,7 +20,9 @@ mod stream_start; mod starttls; pub use starttls::StartTlsClient; mod happy_eyeballs; +mod event; +pub use event::Event; mod client; -pub use client::{Client, ClientEvent}; +pub use client::Client; mod component; -pub use component::{Component, ComponentEvent}; +pub use component::Component;