chore(reth_primitives): Use trait for size methods in primitive types (#12201)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Tuan Tran
2024-11-11 23:54:00 +07:00
committed by GitHub
parent 24b3e63ab3
commit eccff7d24b
16 changed files with 84 additions and 42 deletions

View File

@ -14,6 +14,7 @@ workspace = true
[dependencies]
# reth
reth-primitives.workspace = true
reth-primitives-traits.workspace = true
reth-eth-wire-types.workspace = true
reth-consensus.workspace = true
reth-network-peers.workspace = true
@ -32,7 +33,6 @@ tokio = { workspace = true, features = ["sync"] }
auto_impl.workspace = true
tracing.workspace = true
derive_more.workspace = true
parking_lot = { workspace = true, optional = true }
[dev-dependencies]
@ -47,11 +47,13 @@ test-utils = [
"reth-consensus/test-utils",
"parking_lot",
"reth-network-types/test-utils",
"reth-primitives/test-utils"
"reth-primitives/test-utils",
"reth-primitives-traits/test-utils"
]
std = [
"reth-consensus/std",
"reth-primitives/std",
"alloy-eips/std",
"alloy-primitives/std"
"alloy-primitives/std",
"reth-primitives-traits/std"
]

View File

@ -1,5 +1,6 @@
use alloy_primitives::{BlockNumber, U256};
use reth_primitives::{SealedBlock, SealedHeader};
use reth_primitives_traits::InMemorySize;
/// The block response
#[derive(PartialEq, Eq, Debug, Clone)]
@ -19,15 +20,6 @@ impl BlockResponse {
}
}
/// Calculates a heuristic for the in-memory size of the [`BlockResponse`].
#[inline]
pub fn size(&self) -> usize {
match self {
Self::Full(block) => SealedBlock::size(block),
Self::Empty(header) => SealedHeader::size(header),
}
}
/// Return the block number
pub fn block_number(&self) -> BlockNumber {
self.header().number
@ -41,3 +33,14 @@ impl BlockResponse {
}
}
}
impl InMemorySize for BlockResponse {
/// Calculates a heuristic for the in-memory size of the [`BlockResponse`].
#[inline]
fn size(&self) -> usize {
match self {
Self::Full(block) => SealedBlock::size(block),
Self::Empty(header) => SealedHeader::size(header),
}
}
}