mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor: replace into bound with standalone function (#14512)
This commit is contained in:
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)]
|
||||
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user