Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: clean up fmt::Debug impls #75

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crates/pubsub/src/ix.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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(),
Expand Down
13 changes: 6 additions & 7 deletions crates/pubsub/src/managers/active_sub.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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()
}
}
Expand Down
13 changes: 7 additions & 6 deletions crates/pubsub/src/managers/in_flight.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -15,12 +16,12 @@ pub(crate) struct InFlight {
pub(crate) tx: oneshot::Sender<Result<Response, TransportError>>,
}

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()
}
}

Expand Down
16 changes: 8 additions & 8 deletions crates/rpc-client/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -33,17 +33,17 @@ where
Complete,
}

impl<Params, Conn> Debug for CallState<Params, Conn>
impl<Params, Conn> fmt::Debug for CallState<Params, Conn>
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",
})
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/rpc-types/src/eth/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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()
}
}
Expand Down
13 changes: 5 additions & 8 deletions crates/transport/src/boxed.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -22,17 +22,14 @@ pub struct BoxTransport {

impl BoxTransport {
/// Instantiate a new box transport from a suitable transport.
pub fn new<T>(inner: T) -> Self
where
T: Transport + Clone + Send + Sync,
{
pub fn new<T: Transport + Clone + Send + Sync>(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()
}
}

Expand Down