Skip to content

Commit f6e5829

Browse files
committed
fix: address clippy nursery lints (const fn, map_or, map_or_else)
1 parent 2d88cc4 commit f6e5829

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

api/src/common/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn is_critical_json_rpc_error(
105105
SendRequestError::TransportError(err) => match err {
106106
RpcCallError::Http(e) => {
107107
use reqwest::StatusCode;
108-
e.status().map_or(false, |s| {
108+
e.status().is_some_and(|s| {
109109
!matches!(
110110
s,
111111
StatusCode::REQUEST_TIMEOUT

api/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ pub enum SendRequestError {
288288

289289
impl SendRequestError {
290290
/// Returns the underlying [`RpcError`] if this is a server error.
291-
pub fn as_rpc_error(&self) -> Option<&RpcError> {
291+
pub const fn as_rpc_error(&self) -> Option<&RpcError> {
292292
match self {
293293
Self::ServerError(e) => Some(e),
294294
_ => None,

api/src/rpc_client.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub enum RpcCallError {
4545
}
4646

4747
impl RpcClient {
48-
pub fn new(url: String, client: reqwest::Client) -> Self {
48+
pub const fn new(url: String, client: reqwest::Client) -> Self {
4949
Self { client, url }
5050
}
5151

@@ -78,11 +78,13 @@ impl RpcClient {
7878
return Err(RpcCallError::Rpc(error));
7979
}
8080

81-
match response.result {
82-
Some(value) => serde_json::from_value(value).map_err(RpcCallError::Deserialize),
83-
None => Err(RpcCallError::Deserialize(serde::de::Error::custom(
84-
"response has neither result nor error",
85-
))),
86-
}
81+
response.result.map_or_else(
82+
|| {
83+
Err(RpcCallError::Deserialize(serde::de::Error::custom(
84+
"response has neither result nor error",
85+
)))
86+
},
87+
|value| serde_json::from_value(value).map_err(RpcCallError::Deserialize),
88+
)
8789
}
8890
}

0 commit comments

Comments
 (0)