From 0a34c6c71f9b3e508f9117b3a5d1b925b2e1d0e8 Mon Sep 17 00:00:00 2001 From: Astro Date: Sat, 3 Jun 2017 02:26:44 +0200 Subject: [PATCH] fix stanza events --- src/lib.rs | 9 +++++++-- src/xmpp_codec.rs | 8 ++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f57e7b8f..043c81e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -105,6 +105,7 @@ impl Future for TcpClient { mod tests { use tokio_core::reactor::Core; use futures::{Future, Stream}; + use xmpp_codec::Packet; #[test] fn it_works() { @@ -118,8 +119,12 @@ mod tests { &addr, &core.handle() ).and_then(|stream| { - stream.for_each(|item| { - Ok(println!("stream item: {:?}", item)) + stream.for_each(|event| { + match event { + Packet::Stanza(el) => println!("<< {}", el), + _ => println!("!! {:?}", event), + } + Ok(()) }) }); core.run(client).unwrap(); diff --git a/src/xmpp_codec.rs b/src/xmpp_codec.rs index ec718146..dc7aeb7e 100644 --- a/src/xmpp_codec.rs +++ b/src/xmpp_codec.rs @@ -85,12 +85,12 @@ impl Codec for XMPPCodec { let mut new_root = None; let mut result = None; for event in &mut self.parser { - match &mut self.root { - &mut None => { + match self.root { + None => { // Expecting match event { Ok(xml::Event::ElementStart(start_tag)) => { - new_root = Some(XMPPRoot::new(start_tag)); + self.root = Some(XMPPRoot::new(start_tag)); result = Some(Packet::StreamStart); break }, @@ -103,7 +103,7 @@ impl Codec for XMPPCodec { } } - &mut Some(ref mut root) => { + Some(ref mut root) => { match root.handle_event(event) { None => (), Some(Ok(stanza)) => {