mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
refactor: replace into bound with standalone function (#14512)
This commit is contained in:
@ -200,6 +200,10 @@ impl reth_primitives_traits::serde_bincode_compat::SerdeBincodeCompat for Receip
|
|||||||
fn as_repr(&self) -> Self::BincodeRepr<'_> {
|
fn as_repr(&self) -> Self::BincodeRepr<'_> {
|
||||||
self.clone()
|
self.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
|
||||||
|
repr
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@ -974,6 +974,10 @@ pub mod serde_bincode_compat {
|
|||||||
fn as_repr(&self) -> Self::BincodeRepr<'_> {
|
fn as_repr(&self) -> Self::BincodeRepr<'_> {
|
||||||
self.into()
|
self.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
|
||||||
|
repr.into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@ -218,6 +218,10 @@ impl reth_primitives_traits::serde_bincode_compat::SerdeBincodeCompat for OpRece
|
|||||||
fn as_repr(&self) -> Self::BincodeRepr<'_> {
|
fn as_repr(&self) -> Self::BincodeRepr<'_> {
|
||||||
self.clone()
|
self.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
|
||||||
|
repr
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait for deposit receipt.
|
/// Trait for deposit receipt.
|
||||||
|
|||||||
@ -779,5 +779,9 @@ pub mod serde_bincode_compat {
|
|||||||
fn as_repr(&self) -> Self::BincodeRepr<'_> {
|
fn as_repr(&self) -> Self::BincodeRepr<'_> {
|
||||||
self.into()
|
self.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
|
||||||
|
repr.into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -606,5 +606,9 @@ pub(super) mod serde_bincode_compat {
|
|||||||
fn as_repr(&self) -> Self::BincodeRepr<'_> {
|
fn as_repr(&self) -> Self::BincodeRepr<'_> {
|
||||||
self.into()
|
self.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
|
||||||
|
repr.into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -429,7 +429,7 @@ pub(super) mod serde_bincode_compat {
|
|||||||
From<SealedBlock<'a, T>> for super::SealedBlock<T>
|
From<SealedBlock<'a, T>> for super::SealedBlock<T>
|
||||||
{
|
{
|
||||||
fn from(value: SealedBlock<'a, T>) -> Self {
|
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<'_> {
|
fn as_repr(&self) -> Self::BincodeRepr<'_> {
|
||||||
self.into()
|
self.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
|
||||||
|
repr.into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -274,7 +274,7 @@ pub(super) mod serde_bincode_compat {
|
|||||||
|
|
||||||
impl<'a, H: Sealable + SerdeBincodeCompat> From<SealedHeader<'a, H>> for super::SealedHeader<H> {
|
impl<'a, H: Sealable + SerdeBincodeCompat> From<SealedHeader<'a, H>> for super::SealedHeader<H> {
|
||||||
fn from(value: SealedHeader<'a, H>) -> Self {
|
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<'_> {
|
fn as_repr(&self) -> Self::BincodeRepr<'_> {
|
||||||
self.into()
|
self.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
|
||||||
|
repr.into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@ -15,10 +15,13 @@ pub trait SerdeBincodeCompat: Sized + 'static {
|
|||||||
/// Serde representation of the type for bincode serialization.
|
/// Serde representation of the type for bincode serialization.
|
||||||
///
|
///
|
||||||
/// This type defines the bincode compatible serde format for the type.
|
/// 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
|
/// Convert this type into its bincode representation
|
||||||
fn as_repr(&self) -> Self::BincodeRepr<'_>;
|
fn as_repr(&self) -> Self::BincodeRepr<'_>;
|
||||||
|
|
||||||
|
/// Convert from the bincode representation
|
||||||
|
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SerdeBincodeCompat for alloy_consensus::Header {
|
impl SerdeBincodeCompat for alloy_consensus::Header {
|
||||||
@ -27,6 +30,10 @@ impl SerdeBincodeCompat for alloy_consensus::Header {
|
|||||||
fn as_repr(&self) -> Self::BincodeRepr<'_> {
|
fn as_repr(&self) -> Self::BincodeRepr<'_> {
|
||||||
self.into()
|
self.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
|
||||||
|
repr.into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Type alias for the [`SerdeBincodeCompat::BincodeRepr`] associated type.
|
/// Type alias for the [`SerdeBincodeCompat::BincodeRepr`] associated type.
|
||||||
@ -75,7 +82,7 @@ mod block_bincode {
|
|||||||
for alloy_consensus::Block<T, H>
|
for alloy_consensus::Block<T, H>
|
||||||
{
|
{
|
||||||
fn from(value: Block<'a, T, H>) -> Self {
|
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<'_> {
|
fn as_repr(&self) -> Self::BincodeRepr<'_> {
|
||||||
self.into()
|
self.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
|
||||||
|
repr.into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Bincode-compatible [`alloy_consensus::BlockBody`] serde implementation.
|
/// Bincode-compatible [`alloy_consensus::BlockBody`] serde implementation.
|
||||||
@ -154,8 +165,12 @@ mod block_bincode {
|
|||||||
{
|
{
|
||||||
fn from(value: BlockBody<'a, T, H>) -> Self {
|
fn from(value: BlockBody<'a, T, H>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
transactions: value.transactions.into_iter().map(Into::into).collect(),
|
transactions: value
|
||||||
ommers: value.ommers.into_iter().map(Into::into).collect(),
|
.transactions
|
||||||
|
.into_iter()
|
||||||
|
.map(SerdeBincodeCompat::from_repr)
|
||||||
|
.collect(),
|
||||||
|
ommers: value.ommers.into_iter().map(SerdeBincodeCompat::from_repr).collect(),
|
||||||
withdrawals: value.withdrawals.into_owned(),
|
withdrawals: value.withdrawals.into_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -194,5 +209,9 @@ mod block_bincode {
|
|||||||
fn as_repr(&self) -> Self::BincodeRepr<'_> {
|
fn as_repr(&self) -> Self::BincodeRepr<'_> {
|
||||||
self.into()
|
self.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self {
|
||||||
|
repr.into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user