Skip to content

Commit

Permalink
chore: refactor some match with same arms (alloy-rs#1463)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger authored Oct 16, 2024
1 parent 881d15c commit e201df8
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 34 deletions.
8 changes: 4 additions & 4 deletions crates/eips/src/eip4844/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,11 @@ pub enum BlobTransactionValidationError {
impl std::error::Error for BlobTransactionValidationError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::InvalidProof { .. } => None,
Self::KZGError(source) => Some(source),
Self::NotBlobTransaction { .. } => None,
Self::MissingSidecar { .. } => None,
Self::WrongVersionedHash { .. } => None,
Self::InvalidProof { .. }
| Self::NotBlobTransaction { .. }
| Self::MissingSidecar { .. }
| Self::WrongVersionedHash { .. } => None,
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/provider/src/layers/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,7 @@ impl<Params: RpcParam> RequestType<Params> {
const fn has_block_tag(&self) -> bool {
if let Some(block_id) = self.block_id {
match block_id {
BlockId::Hash(_) => return false,
BlockId::Number(BlockNumberOrTag::Number(_)) => return false,
BlockId::Hash(_) | BlockId::Number(BlockNumberOrTag::Number(_)) => return false,
_ => return true,
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/pubsub/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ impl ConnectionInterface {
/// requests.
pub async fn recv_from_frontend(&mut self) -> Option<Box<RawValue>> {
match self.shutdown.try_recv() {
Ok(_) => return None,
Err(TryRecvError::Closed) => return None,
Ok(_) | Err(TryRecvError::Closed) => return None,
Err(TryRecvError::Empty) => {}
}

Expand Down
17 changes: 7 additions & 10 deletions crates/rpc-types-engine/src/forkchoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,13 @@ impl From<ForkchoiceUpdateError> for jsonrpsee_types::error::ErrorObject<'static
None::<()>,
)
}
ForkchoiceUpdateError::InvalidState => jsonrpsee_types::error::ErrorObject::owned(
INVALID_FORK_CHOICE_STATE_ERROR,
INVALID_FORK_CHOICE_STATE_ERROR_MSG,
None::<()>,
),
ForkchoiceUpdateError::UnknownFinalBlock => jsonrpsee_types::error::ErrorObject::owned(
INVALID_FORK_CHOICE_STATE_ERROR,
INVALID_FORK_CHOICE_STATE_ERROR_MSG,
None::<()>,
),
ForkchoiceUpdateError::InvalidState | ForkchoiceUpdateError::UnknownFinalBlock => {
jsonrpsee_types::error::ErrorObject::owned(
INVALID_FORK_CHOICE_STATE_ERROR,
INVALID_FORK_CHOICE_STATE_ERROR_MSG,
None::<()>,
)
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/rpc-types-engine/src/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ impl std::error::Error for JwtError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::JwtSecretHexDecodeError(err) => Some(err),
Self::CreateDir { source, .. } => Some(source),
Self::Read { source, .. } => Some(source),
Self::Write { source, .. } => Some(source),
Self::CreateDir { source, .. }
| Self::Read { source, .. }
| Self::Write { source, .. } => Some(source),
_ => None,
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/rpc-types-eth/src/transaction/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ impl std::error::Error for ConversionError {
match self {
Self::Eip2718Error(err) => Some(err),
Self::SignatureError(err) => Some(err),
Self::BaseFeePerGasConversion(err) => Some(err),
Self::GasLimitConversion(err) => Some(err),
Self::GasUsedConversion(err) => Some(err),
Self::BlobGasUsedConversion(err) => Some(err),
Self::ExcessBlobGasConversion(err) => Some(err),
Self::BaseFeePerGasConversion(err)
| Self::GasLimitConversion(err)
| Self::GasUsedConversion(err)
| Self::BlobGasUsedConversion(err)
| Self::ExcessBlobGasConversion(err) => Some(err),
_ => None,
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/rpc-types-trace/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ impl<Ok, Err> TraceResult<Ok, Err> {
#[doc(alias = "transaction_hash")]
pub const fn tx_hash(&self) -> Option<TxHash> {
*match self {
Self::Success { tx_hash, .. } => tx_hash,
Self::Error { tx_hash, .. } => tx_hash,
Self::Success { tx_hash, .. } | Self::Error { tx_hash, .. } => tx_hash,
}
}

Expand Down
4 changes: 1 addition & 3 deletions crates/rpc-types-txpool/src/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ impl Visitor<'_> for TxpoolInspectSummaryVisitor {
return Err(de::Error::custom("invalid format for TxpoolInspectSummary: gas_price"));
}
let to = match addr_split[0] {
"" => None,
"0x" => None,
"contract creation" => None,
"" | "0x" | "contract creation" => None,
addr => {
Some(Address::from_str(addr.trim_start_matches("0x")).map_err(de::Error::custom)?)
}
Expand Down
4 changes: 1 addition & 3 deletions crates/transport-ws/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ impl WsBackend<TungsteniteStream> {
error!("Received binary message, expected text");
Err(())
}
Message::Ping(_) => Ok(()),
Message::Pong(_) => Ok(()),
Message::Frame(_) => Ok(()),
Message::Ping(_) | Message::Pong(_) | Message::Frame(_) => Ok(()),
}
}

Expand Down

0 comments on commit e201df8

Please sign in to comment.