From 700941bfa07472bb2d56178b25b8a4ee6872add3 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Tue, 12 Dec 2023 08:04:17 +0100 Subject: [PATCH] chore: clean up fmt::Debug impls --- crates/pubsub/src/ix.rs | 5 +++-- crates/pubsub/src/managers/active_sub.rs | 13 ++++++------- crates/pubsub/src/managers/in_flight.rs | 13 +++++++------ crates/rpc-client/src/call.rs | 16 ++++++++-------- crates/rpc-types/src/eth/block.rs | 6 +++--- crates/transport/src/boxed.rs | 13 +++++-------- 6 files changed, 32 insertions(+), 34 deletions(-) diff --git a/crates/pubsub/src/ix.rs b/crates/pubsub/src/ix.rs index cfa65812f81..9bd1f517518 100644 --- a/crates/pubsub/src/ix.rs +++ b/crates/pubsub/src/ix.rs @@ -1,6 +1,7 @@ use crate::managers::InFlight; use alloy_primitives::U256; use serde_json::value::RawValue; +use std::fmt; use tokio::sync::{broadcast, oneshot}; /// Instructions for the pubsub service. @@ -13,8 +14,8 @@ pub(crate) enum PubSubInstruction { Unsubscribe(U256), } -impl std::fmt::Debug for PubSubInstruction { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Debug for PubSubInstruction { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Request(arg0) => f.debug_tuple("Request").field(arg0).finish(), Self::GetSub(arg0, _) => f.debug_tuple("GetSub").field(arg0).finish(), diff --git a/crates/pubsub/src/managers/active_sub.rs b/crates/pubsub/src/managers/active_sub.rs index 642cbd89320..5a7096b9561 100644 --- a/crates/pubsub/src/managers/active_sub.rs +++ b/crates/pubsub/src/managers/active_sub.rs @@ -1,7 +1,7 @@ use alloy_json_rpc::SerializedRequest; use alloy_primitives::B256; use serde_json::value::RawValue; -use std::hash::Hash; +use std::{fmt, hash::Hash}; use tokio::sync::broadcast; #[derive(Clone)] @@ -43,13 +43,12 @@ impl Ord for ActiveSubscription { } } -impl std::fmt::Debug for ActiveSubscription { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let channel_desc = format!("Channel status: {} subscribers", self.tx.receiver_count()); - +impl fmt::Debug for ActiveSubscription { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("ActiveSubscription") - .field("req", &self.request) - .field("tx", &channel_desc) + .field("local_id", &self.local_id) + .field("request", &self.request) + .field("subscribers", &self.tx.receiver_count()) .finish() } } diff --git a/crates/pubsub/src/managers/in_flight.rs b/crates/pubsub/src/managers/in_flight.rs index 9ab992d4ae3..4cb253466c5 100644 --- a/crates/pubsub/src/managers/in_flight.rs +++ b/crates/pubsub/src/managers/in_flight.rs @@ -1,6 +1,7 @@ use alloy_json_rpc::{Response, ResponsePayload, SerializedRequest}; use alloy_primitives::U256; use alloy_transport::TransportError; +use std::fmt; use tokio::sync::oneshot; /// An in-flight JSON-RPC request. @@ -15,12 +16,12 @@ pub(crate) struct InFlight { pub(crate) tx: oneshot::Sender>, } -impl std::fmt::Debug for InFlight { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let channel_desc = - format!("Channel status: {}", if self.tx.is_closed() { "closed" } else { "ok" }); - - f.debug_struct("InFlight").field("req", &self.request).field("tx", &channel_desc).finish() +impl fmt::Debug for InFlight { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("InFlight") + .field("request", &self.request) + .field("tx_is_closed", &self.tx.is_closed()) + .finish() } } diff --git a/crates/rpc-client/src/call.rs b/crates/rpc-client/src/call.rs index 59dee1e91a9..6ea8b333406 100644 --- a/crates/rpc-client/src/call.rs +++ b/crates/rpc-client/src/call.rs @@ -6,7 +6,7 @@ use alloy_transport::{RpcFut, Transport, TransportError, TransportResult}; use core::panic; use serde_json::value::RawValue; use std::{ - fmt::Debug, + fmt, future::Future, marker::PhantomData, pin::Pin, @@ -33,17 +33,17 @@ where Complete, } -impl Debug for CallState +impl fmt::Debug for CallState where Params: RpcParam, Conn: Transport + Clone, { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Self::Prepared { .. } => f.debug_struct("Prepared").finish(), - Self::AwaitingResponse { .. } => f.debug_struct("AwaitingResponse").finish(), - Self::Complete => write!(f, "Complete"), - } + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(match self { + Self::Prepared { .. } => "Prepared", + Self::AwaitingResponse { .. } => "AwaitingResponse", + Self::Complete => "Complete", + }) } } diff --git a/crates/rpc-types/src/eth/block.rs b/crates/rpc-types/src/eth/block.rs index 12cd1a7a209..59e71d39135 100644 --- a/crates/rpc-types/src/eth/block.rs +++ b/crates/rpc-types/src/eth/block.rs @@ -485,7 +485,7 @@ impl<'de> Deserialize<'de> for BlockId { impl<'de> Visitor<'de> for BlockIdVisitor { type Value = BlockId; - fn expecting(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result { + fn expecting(&self, formatter: &mut Formatter<'_>) -> fmt::Result { formatter.write_str("Block identifier following EIP-1898") } @@ -574,8 +574,8 @@ pub struct BlockNumHash { /// Block number and hash of the forked block. pub type ForkBlock = BlockNumHash; -impl std::fmt::Debug for BlockNumHash { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Debug for BlockNumHash { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("").field(&self.number).field(&self.hash).finish() } } diff --git a/crates/transport/src/boxed.rs b/crates/transport/src/boxed.rs index 38257d58a69..8653423b837 100644 --- a/crates/transport/src/boxed.rs +++ b/crates/transport/src/boxed.rs @@ -1,6 +1,6 @@ use crate::{Transport, TransportError, TransportFut}; use alloy_json_rpc::{RequestPacket, ResponsePacket}; -use std::fmt::Debug; +use std::fmt; use tower::Service; /// A boxed, Clone-able [`Transport`] trait object. @@ -22,17 +22,14 @@ pub struct BoxTransport { impl BoxTransport { /// Instantiate a new box transport from a suitable transport. - pub fn new(inner: T) -> Self - where - T: Transport + Clone + Send + Sync, - { + pub fn new(inner: T) -> Self { Self { inner: Box::new(inner) } } } -impl Debug for BoxTransport { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("BoxTransport").finish() +impl fmt::Debug for BoxTransport { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("BoxTransport").finish_non_exhaustive() } }