mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: replace BincodeRepr From bound with conversion function (#14069)
This commit is contained in:
@ -602,5 +602,9 @@ pub(super) mod serde_bincode_compat {
|
||||
SerdeBincodeCompat for super::RecoveredBlock<T>
|
||||
{
|
||||
type BincodeRepr<'a> = RecoveredBlock<'a, T>;
|
||||
|
||||
fn as_repr(&self) -> Self::BincodeRepr<'_> {
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -421,7 +421,7 @@ pub(super) mod serde_bincode_compat {
|
||||
From<&'a super::SealedBlock<T>> for SealedBlock<'a, T>
|
||||
{
|
||||
fn from(value: &'a super::SealedBlock<T>) -> Self {
|
||||
Self { header: (&value.header).into(), body: (&value.body).into() }
|
||||
Self { header: value.header.as_repr(), body: value.body.as_repr() }
|
||||
}
|
||||
}
|
||||
|
||||
@ -459,5 +459,9 @@ pub(super) mod serde_bincode_compat {
|
||||
SerdeBincodeCompat for super::SealedBlock<T>
|
||||
{
|
||||
type BincodeRepr<'a> = SealedBlock<'a, T>;
|
||||
|
||||
fn as_repr(&self) -> Self::BincodeRepr<'_> {
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -268,7 +268,7 @@ pub(super) mod serde_bincode_compat {
|
||||
for SealedHeader<'a, H>
|
||||
{
|
||||
fn from(value: &'a super::SealedHeader<H>) -> Self {
|
||||
Self { hash: value.hash(), header: (&value.header).into() }
|
||||
Self { hash: value.hash(), header: value.header.as_repr() }
|
||||
}
|
||||
}
|
||||
|
||||
@ -298,6 +298,9 @@ pub(super) mod serde_bincode_compat {
|
||||
|
||||
impl<H: Sealable + SerdeBincodeCompat> SerdeBincodeCompat for super::SealedHeader<H> {
|
||||
type BincodeRepr<'a> = SealedHeader<'a, H>;
|
||||
fn as_repr(&self) -> Self::BincodeRepr<'_> {
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@ -15,11 +15,18 @@ 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 + From<&'a Self> + Into<Self>;
|
||||
type BincodeRepr<'a>: Debug + Serialize + DeserializeOwned + Into<Self>;
|
||||
|
||||
/// Convert this type into its bincode representation
|
||||
fn as_repr(&self) -> Self::BincodeRepr<'_>;
|
||||
}
|
||||
|
||||
impl SerdeBincodeCompat for alloy_consensus::Header {
|
||||
type BincodeRepr<'a> = alloy_consensus::serde_bincode_compat::Header<'a>;
|
||||
|
||||
fn as_repr(&self) -> Self::BincodeRepr<'_> {
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
|
||||
/// Type alias for the [`SerdeBincodeCompat::BincodeRepr`] associated type.
|
||||
@ -61,7 +68,7 @@ mod block_bincode {
|
||||
for Block<'a, T, H>
|
||||
{
|
||||
fn from(value: &'a alloy_consensus::Block<T, H>) -> Self {
|
||||
Self { header: (&value.header).into(), body: (&value.body).into() }
|
||||
Self { header: value.header.as_repr(), body: (&value.body).into() }
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,6 +109,10 @@ mod block_bincode {
|
||||
for alloy_consensus::Block<T, H>
|
||||
{
|
||||
type BincodeRepr<'a> = Block<'a, T, H>;
|
||||
|
||||
fn as_repr(&self) -> Self::BincodeRepr<'_> {
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
|
||||
/// Bincode-compatible [`alloy_consensus::BlockBody`] serde implementation.
|
||||
@ -130,7 +141,7 @@ mod block_bincode {
|
||||
impl<'a, T: SerdeBincodeCompat> From<&'a alloy_consensus::BlockBody<T>> for BlockBody<'a, T> {
|
||||
fn from(value: &'a alloy_consensus::BlockBody<T>) -> Self {
|
||||
Self {
|
||||
transactions: value.transactions.iter().map(Into::into).collect(),
|
||||
transactions: value.transactions.iter().map(|tx| tx.as_repr()).collect(),
|
||||
ommers: value.ommers.iter().map(Into::into).collect(),
|
||||
withdrawals: Cow::Borrowed(&value.withdrawals),
|
||||
}
|
||||
@ -172,5 +183,9 @@ mod block_bincode {
|
||||
|
||||
impl<T: SerdeBincodeCompat> SerdeBincodeCompat for alloy_consensus::BlockBody<T> {
|
||||
type BincodeRepr<'a> = BlockBody<'a, T>;
|
||||
|
||||
fn as_repr(&self) -> Self::BincodeRepr<'_> {
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user