diff options
| author | acdenisSK <[email protected]> | 2017-07-30 23:10:54 +0200 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-07-30 23:10:54 +0200 |
| commit | db8179960cd8b52549500e8f0fe980236bd5d381 (patch) | |
| tree | 47226003b788ae9428d77f660b2fa1ee01c4ce31 /src | |
| parent | Remove a few clones (diff) | |
| download | serenity-db8179960cd8b52549500e8f0fe980236bd5d381.tar.xz serenity-db8179960cd8b52549500e8f0fe980236bd5d381.zip | |
Handle the `None`s better
Diffstat (limited to 'src')
| -rw-r--r-- | src/internal/ws_impl.rs | 11 |
1 files changed, 8 insertions, 3 deletions
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<F, T>(&mut self, decode: F) -> Result<T> where F: FnOnce(Value) -> Result<T>; + fn recv_json<F, T>(&mut self, decode: F) -> Result<T> where F: Fn(Value) -> Result<T>; } pub trait SenderExt { @@ -16,7 +16,7 @@ pub trait SenderExt { impl ReceiverExt for WsClient<TlsStream<TcpStream>> { fn recv_json<F, T>(&mut self, decode: F) -> Result<T> - where F: FnOnce(Value) -> Result<T> { + where F: Fn(Value) -> Result<T> { let message = self.recv_message()?; let res = match message { @@ -50,7 +50,12 @@ impl ReceiverExt for WsClient<TlsStream<TcpStream>> { 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), + } } } |