From a45bbec25952a15cacb105b536432d6fbe3fb7b1 Mon Sep 17 00:00:00 2001 From: hozan23 Date: Sun, 30 Jun 2024 04:42:07 +0200 Subject: jsonrpc: remove unwrap() and use expect() for examples, docs, and tests --- jsonrpc/src/client/message_dispatcher.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'jsonrpc/src/client/message_dispatcher.rs') diff --git a/jsonrpc/src/client/message_dispatcher.rs b/jsonrpc/src/client/message_dispatcher.rs index f370985..53dd9e5 100644 --- a/jsonrpc/src/client/message_dispatcher.rs +++ b/jsonrpc/src/client/message_dispatcher.rs @@ -48,10 +48,13 @@ impl MessageDispatcher { /// If a channel is registered for the response's ID, the response is sent /// through that channel. If no channel is found for the ID, returns an error. pub(super) async fn dispatch(&self, res: message::Response) -> Result<()> { - if res.id.is_none() { - return Err(Error::InvalidMsg("Response id is none")); - } - let id: RequestID = serde_json::from_value(res.id.clone().unwrap())?; + let res_id = match res.id { + Some(ref rid) => rid.clone(), + None => { + return Err(Error::InvalidMsg("Response id is none")); + } + }; + let id: RequestID = serde_json::from_value(res_id)?; let val = self.chans.lock().await.remove(&id); match val { Some(tx) => tx.send(res).await.map_err(Error::from), -- cgit v1.2.3