diff options
author | hozan23 <hozan23@karyontech.net> | 2024-06-30 04:42:07 +0200 |
---|---|---|
committer | hozan23 <hozan23@karyontech.net> | 2024-06-30 04:42:07 +0200 |
commit | a45bbec25952a15cacb105b536432d6fbe3fb7b1 (patch) | |
tree | 280072dee7350b8a8deca081906f39f50e4dadba /jsonrpc/src/client/message_dispatcher.rs | |
parent | f842b0fc733b48d83d127bf06b264a781e725116 (diff) |
jsonrpc: remove unwrap() and use expect() for examples, docs, and tests
Diffstat (limited to 'jsonrpc/src/client/message_dispatcher.rs')
-rw-r--r-- | jsonrpc/src/client/message_dispatcher.rs | 11 |
1 files changed, 7 insertions, 4 deletions
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), |