Repository: paradigmxyz/reth (language: rust)

Issue:
replace Into<Self> bound with standalone function
### Describe the feature

due to Into<Self> we can't use `&Self` as the compat type 

https://github.com/paradigmxyz/reth/blob/16c3c5b733702f31daa4bf4e2c688ce37ccd5b58/crates/primitives-traits/src/serde_bincode_compat.rs#L15-L21

similar limitation why we added `as_repr`, now we need to introduce

```rust
from_repr
```

and replace the Into bound with that, this way we can use &Self as the compat

## TODO
* replace Into<Self> with `from_repr(Self::BincodeRepr<'_>) -> Self` 
* update all impls

### Additional context

_No response_


Discussion / hints:
Hey, I'd like to work on this
assigned, ty

btw haven't forgotten about #13621 just need to run some checks to wrap it up
np, yeah that probably needs some time to check and review

Fix patch:
diff --git a/crates/ethereum/primitives/src/receipt.rs b/crates/ethereum/primitives/src/receipt.rs
index e364a13aef20..aabecf4b9b1a 100644
--- a/crates/ethereum/primitives/src/receipt.rs
+++ b/crates/ethereum/primitives/src/receipt.rs
@@ -200,6 +200,10 @@ impl reth_primitives_traits::serde_bincode_compat::SerdeBincodeCompat for Receip
     fn as_repr(&self) -> Self::BincodeRepr<'_> {
         self.clone()
     }
+
+    fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
+        repr
+    }
 }
 
 #[cfg(test)]
diff --git a/crates/ethereum/primitives/src/transaction.rs b/crates/ethereum/primitives/src/transaction.rs
index 159be023b4e6..7a481d3b641e 100644
--- a/crates/ethereum/primitives/src/transaction.rs
+++ b/crates/ethereum/primitives/src/transaction.rs
@@ -974,6 +974,10 @@ pub mod serde_bincode_compat {
         fn as_repr(&self) -> Self::BincodeRepr<'_> {
             self.into()
         }
+
+        fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
+            repr.into()
+        }
     }
 
     #[cfg(test)]
diff --git a/crates/optimism/primitives/src/receipt.rs b/crates/optimism/primitives/src/receipt.rs
index 019095dbcc86..05033592cd99 100644
--- a/crates/optimism/primitives/src/receipt.rs
+++ b/crates/optimism/primitives/src/receipt.rs
@@ -218,6 +218,10 @@ impl reth_primitives_traits::serde_bincode_compat::SerdeBincodeCompat for OpRece
     fn as_repr(&self) -> Self::BincodeRepr<'_> {
         self.clone()
     }
+
+    fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
+        repr
+    }
 }
 
 /// Trait for deposit receipt.
diff --git a/crates/optimism/primitives/src/transaction/signed.rs b/crates/optimism/primitives/src/transaction/signed.rs
index 64790226b928..688eb9f663bd 100644
--- a/crates/optimism/primitives/src/transaction/signed.rs
+++ b/crates/optimism/primitives/src/transaction/signed.rs
@@ -779,5 +779,9 @@ pub mod serde_bincode_compat {
         fn as_repr(&self) -> Self::BincodeRepr<'_> {
             self.into()
         }
+
+        fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
+            repr.into()
+        }
     }
 }
diff --git a/crates/primitives-traits/src/block/recovered.rs b/crates/primitives-traits/src/block/recovered.rs
index e2c53a601143..934a59884d37 100644
--- a/crates/primitives-traits/src/block/recovered.rs
+++ b/crates/primitives-traits/src/block/recovered.rs
@@ -606,5 +606,9 @@ pub(super) mod serde_bincode_compat {
         fn as_repr(&self) -> Self::BincodeRepr<'_> {
             self.into()
         }
+
+        fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
+            repr.into()
+        }
     }
 }
diff --git a/crates/primitives-traits/src/block/sealed.rs b/crates/primitives-traits/src/block/sealed.rs
index 4a12556cb1d0..3f50d7f90077 100644
--- a/crates/primitives-traits/src/block/sealed.rs
+++ b/crates/primitives-traits/src/block/sealed.rs
@@ -429,7 +429,7 @@ pub(super) mod serde_bincode_compat {
         From<SealedBlock<'a, T>> for super::SealedBlock<T>
     {
         fn from(value: SealedBlock<'a, T>) -> Self {
-            Self::from_sealed_parts(value.header.into(), value.body.into())
+            Self::from_sealed_parts(value.header.into(), SerdeBincodeCompat::from_repr(value.body))
         }
     }
 
@@ -463,5 +463,9 @@ pub(super) mod serde_bincode_compat {
         fn as_repr(&self) -> Self::BincodeRepr<'_> {
             self.into()
         }
+
+        fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
+            repr.into()
+        }
     }
 }
diff --git a/crates/primitives-traits/src/header/sealed.rs b/crates/primitives-traits/src/header/sealed.rs
index 8f12ea4254b4..dc59c1f06ebc 100644
--- a/crates/primitives-traits/src/header/sealed.rs
+++ b/crates/primitives-traits/src/header/sealed.rs
@@ -274,7 +274,7 @@ pub(super) mod serde_bincode_compat {
 
     impl<'a, H: Sealable + SerdeBincodeCompat> From<SealedHeader<'a, H>> for super::SealedHeader<H> {
         fn from(value: SealedHeader<'a, H>) -> Self {
-            Self::new(value.header.into(), value.hash)
+            Self::new(SerdeBincodeCompat::from_repr(value.header), value.hash)
         }
     }
 
@@ -301,6 +301,10 @@ pub(super) mod serde_bincode_compat {
         fn as_repr(&self) -> Self::BincodeRepr<'_> {
             self.into()
         }
+
+        fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
+            repr.into()
+        }
     }
 
     #[cfg(test)]
diff --git a/crates/primitives-traits/src/serde_bincode_compat.rs b/crates/primitives-traits/src/serde_bincode_compat.rs
index 8e5e8936bf0c..fe5a1822df77 100644
--- a/crates/primitives-traits/src/serde_bincode_compat.rs
+++ b/crates/primitives-traits/src/serde_bincode_compat.rs
@@ -15,10 +15,13 @@ pub trait SerdeBincodeCompat: Sized + 'static {
     /// Serde representation of the type for bincode serialization.
     ///
     /// This type defines the bincode compatible serde format for the type.
-    type BincodeRepr<'a>: Debug + Serialize + DeserializeOwned + Into<Self>;
+    type BincodeRepr<'a>: Debug + Serialize + DeserializeOwned;
 
     /// Convert this type into its bincode representation
     fn as_repr(&self) -> Self::BincodeRepr<'_>;
+
+    /// Convert from the bincode representation
+    fn from_repr(repr: Self::BincodeRepr<'_>) -> Self;
 }
 
 impl SerdeBincodeCompat for alloy_consensus::Header {
@@ -27,6 +30,10 @@ impl SerdeBincodeCompat for alloy_consensus::Header {
     fn as_repr(&self) -> Self::BincodeRepr<'_> {
         self.into()
     }
+
+    fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
+        repr.into()
+    }
 }
 
 /// Type alias for the [`SerdeBincodeCompat::BincodeRepr`] associated type.
@@ -75,7 +82,7 @@ mod block_bincode {
         for alloy_consensus::Block<T, H>
     {
         fn from(value: Block<'a, T, H>) -> Self {
-            Self { header: value.header.into(), body: value.body.into() }
+            Self { header: SerdeBincodeCompat::from_repr(value.header), body: value.body.into() }
         }
     }
 
@@ -112,6 +119,10 @@ mod block_bincode {
         fn as_repr(&self) -> Self::BincodeRepr<'_> {
             self.into()
         }
+
+        fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
+            repr.into()
+        }
     }
 
     /// Bincode-compatible [`alloy_consensus::BlockBody`] serde implementation.
@@ -154,8 +165,12 @@ mod block_bincode {
     {
         fn from(value: BlockBody<'a, T, H>) -> Self {
             Self {
-                transactions: value.transactions.into_iter().map(Into::into).collect(),
-                ommers: value.ommers.into_iter().map(Into::into).collect(),
+                transactions: value
+                    .transactions
+                    .into_iter()
+                    .map(SerdeBincodeCompat::from_repr)
+                    .collect(),
+                ommers: value.ommers.into_iter().map(SerdeBincodeCompat::from_repr).collect(),
                 withdrawals: value.withdrawals.into_owned(),
             }
         }
@@ -194,5 +209,9 @@ mod block_bincode {
         fn as_repr(&self) -> Self::BincodeRepr<'_> {
             self.into()
         }
+
+        fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
+            repr.into()
+        }
     }
 }


Test patch: