From db8179960cd8b52549500e8f0fe980236bd5d381 Mon Sep 17 00:00:00 2001 From: acdenisSK Date: Sun, 30 Jul 2017 23:10:54 +0200 Subject: Handle the `None`s better --- src/internal/ws_impl.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/internal') diff --git a/src/internal/ws_impl.rs b/src/internal/ws_impl.rs index b20f0a6..2684f45 100644 --- a/src/internal/ws_impl.rs +++ b/src/internal/ws_impl.rs @@ -7,7 +7,7 @@ use gateway::GatewayError; use internal::prelude::*; pub trait ReceiverExt { - fn recv_json(&mut self, decode: F) -> Result where F: FnOnce(Value) -> Result; + fn recv_json(&mut self, decode: F) -> Result where F: Fn(Value) -> Result; } pub trait SenderExt { @@ -16,7 +16,7 @@ pub trait SenderExt { impl ReceiverExt for WsClient> { fn recv_json(&mut self, decode: F) -> Result - where F: FnOnce(Value) -> Result { + where F: Fn(Value) -> Result { let message = self.recv_message()?; let res = match message { @@ -50,7 +50,12 @@ impl ReceiverExt for WsClient> { OwnedMessage::Pong(_) => None, }; - res.unwrap() + // As to ignore the `None`s returned from `Ping` and `Pong`. + // Since they're essentially useless to us anyway. + match res { + Some(data) => data, + None => self.recv_json(decode), + } } } -- cgit v1.2.3