Skip to content

Commit cb615cf

Browse files
refactor: replace into bound with standalone function (#14512)
1 parent 0f4914a commit cb615cf

File tree

8 files changed

+53
-6
lines changed

8 files changed

+53
-6
lines changed

crates/ethereum/primitives/src/receipt.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ impl reth_primitives_traits::serde_bincode_compat::SerdeBincodeCompat for Receip
200200
fn as_repr(&self) -> Self::BincodeRepr<'_> {
201201
self.clone()
202202
}
203+
204+
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
205+
repr
206+
}
203207
}
204208

205209
#[cfg(test)]

crates/ethereum/primitives/src/transaction.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,10 @@ pub mod serde_bincode_compat {
974974
fn as_repr(&self) -> Self::BincodeRepr<'_> {
975975
self.into()
976976
}
977+
978+
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
979+
repr.into()
980+
}
977981
}
978982

979983
#[cfg(test)]

crates/optimism/primitives/src/receipt.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ impl reth_primitives_traits::serde_bincode_compat::SerdeBincodeCompat for OpRece
218218
fn as_repr(&self) -> Self::BincodeRepr<'_> {
219219
self.clone()
220220
}
221+
222+
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
223+
repr
224+
}
221225
}
222226

223227
/// Trait for deposit receipt.

crates/optimism/primitives/src/transaction/signed.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,5 +779,9 @@ pub mod serde_bincode_compat {
779779
fn as_repr(&self) -> Self::BincodeRepr<'_> {
780780
self.into()
781781
}
782+
783+
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
784+
repr.into()
785+
}
782786
}
783787
}

crates/primitives-traits/src/block/recovered.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,5 +606,9 @@ pub(super) mod serde_bincode_compat {
606606
fn as_repr(&self) -> Self::BincodeRepr<'_> {
607607
self.into()
608608
}
609+
610+
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
611+
repr.into()
612+
}
609613
}
610614
}

crates/primitives-traits/src/block/sealed.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ pub(super) mod serde_bincode_compat {
429429
From<SealedBlock<'a, T>> for super::SealedBlock<T>
430430
{
431431
fn from(value: SealedBlock<'a, T>) -> Self {
432-
Self::from_sealed_parts(value.header.into(), value.body.into())
432+
Self::from_sealed_parts(value.header.into(), SerdeBincodeCompat::from_repr(value.body))
433433
}
434434
}
435435

@@ -463,5 +463,9 @@ pub(super) mod serde_bincode_compat {
463463
fn as_repr(&self) -> Self::BincodeRepr<'_> {
464464
self.into()
465465
}
466+
467+
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
468+
repr.into()
469+
}
466470
}
467471
}

crates/primitives-traits/src/header/sealed.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ pub(super) mod serde_bincode_compat {
274274

275275
impl<'a, H: Sealable + SerdeBincodeCompat> From<SealedHeader<'a, H>> for super::SealedHeader<H> {
276276
fn from(value: SealedHeader<'a, H>) -> Self {
277-
Self::new(value.header.into(), value.hash)
277+
Self::new(SerdeBincodeCompat::from_repr(value.header), value.hash)
278278
}
279279
}
280280

@@ -301,6 +301,10 @@ pub(super) mod serde_bincode_compat {
301301
fn as_repr(&self) -> Self::BincodeRepr<'_> {
302302
self.into()
303303
}
304+
305+
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
306+
repr.into()
307+
}
304308
}
305309

306310
#[cfg(test)]

crates/primitives-traits/src/serde_bincode_compat.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ pub trait SerdeBincodeCompat: Sized + 'static {
1515
/// Serde representation of the type for bincode serialization.
1616
///
1717
/// This type defines the bincode compatible serde format for the type.
18-
type BincodeRepr<'a>: Debug + Serialize + DeserializeOwned + Into<Self>;
18+
type BincodeRepr<'a>: Debug + Serialize + DeserializeOwned;
1919

2020
/// Convert this type into its bincode representation
2121
fn as_repr(&self) -> Self::BincodeRepr<'_>;
22+
23+
/// Convert from the bincode representation
24+
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self;
2225
}
2326

2427
impl SerdeBincodeCompat for alloy_consensus::Header {
@@ -27,6 +30,10 @@ impl SerdeBincodeCompat for alloy_consensus::Header {
2730
fn as_repr(&self) -> Self::BincodeRepr<'_> {
2831
self.into()
2932
}
33+
34+
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
35+
repr.into()
36+
}
3037
}
3138

3239
/// Type alias for the [`SerdeBincodeCompat::BincodeRepr`] associated type.
@@ -75,7 +82,7 @@ mod block_bincode {
7582
for alloy_consensus::Block<T, H>
7683
{
7784
fn from(value: Block<'a, T, H>) -> Self {
78-
Self { header: value.header.into(), body: value.body.into() }
85+
Self { header: SerdeBincodeCompat::from_repr(value.header), body: value.body.into() }
7986
}
8087
}
8188

@@ -112,6 +119,10 @@ mod block_bincode {
112119
fn as_repr(&self) -> Self::BincodeRepr<'_> {
113120
self.into()
114121
}
122+
123+
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
124+
repr.into()
125+
}
115126
}
116127

117128
/// Bincode-compatible [`alloy_consensus::BlockBody`] serde implementation.
@@ -154,8 +165,12 @@ mod block_bincode {
154165
{
155166
fn from(value: BlockBody<'a, T, H>) -> Self {
156167
Self {
157-
transactions: value.transactions.into_iter().map(Into::into).collect(),
158-
ommers: value.ommers.into_iter().map(Into::into).collect(),
168+
transactions: value
169+
.transactions
170+
.into_iter()
171+
.map(SerdeBincodeCompat::from_repr)
172+
.collect(),
173+
ommers: value.ommers.into_iter().map(SerdeBincodeCompat::from_repr).collect(),
159174
withdrawals: value.withdrawals.into_owned(),
160175
}
161176
}
@@ -194,5 +209,9 @@ mod block_bincode {
194209
fn as_repr(&self) -> Self::BincodeRepr<'_> {
195210
self.into()
196211
}
212+
213+
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
214+
repr.into()
215+
}
197216
}
198217
}

0 commit comments

Comments
 (0)