Skip to content

Commit

Permalink
chore: collapse Debug for OtherFields (alloy-rs#702)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored and ben186 committed Jul 27, 2024
1 parent 0a7a295 commit 624067d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions crates/rpc-types/src/eth/other.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_json::Map;
use std::{
collections::BTreeMap,
fmt,
ops::{Deref, DerefMut},
};

/// A type that is supposed to capture additional fields that are not native to ethereum but included in ethereum adjacent networks, for example fields the [optimism `eth_getTransactionByHash` request](https://docs.alchemy.com/alchemy/apis/optimism/eth-gettransactionbyhash) returns additional fields that this type will capture
///
/// This type is supposed to be used with [`#[serde(flatten)`](https://serde.rs/field-attrs.html#flatten)
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(transparent)]
pub struct OtherFields {
/// Contains all unknown fields
inner: BTreeMap<String, serde_json::Value>,
}

// === impl OtherFields ===

impl OtherFields {
/// Creates a new instance
pub fn new(inner: BTreeMap<String, serde_json::Value>) -> Self {
Expand Down Expand Up @@ -82,6 +81,13 @@ impl OtherFields {
}
}

impl fmt::Debug for OtherFields {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("OtherFields ")?;
self.inner.fmt(f)
}
}

impl TryFrom<serde_json::Value> for OtherFields {
type Error = serde_json::Error;

Expand Down

0 comments on commit 624067d

Please sign in to comment.