Rework InspectState (#7271)

Reworks `InspectState` in two ways:
- Renames `inspect_with` to `inspect_state` to reflect the trait name.
- Make `inspect_state` return the result of the closure
This commit is contained in:
Bastian Köcher
2020-10-07 01:16:14 +02:00
committed by GitHub
parent 2cf4fb2cbc
commit 89e06d26b2
2 changed files with 8 additions and 4 deletions
+4 -2
View File
@@ -133,8 +133,10 @@ impl core::Benchmark for ImportBenchmark {
let elapsed = start.elapsed();
// Sanity checks.
context.client.state_at(&BlockId::number(1)).expect("state_at failed for block#1")
.inspect_with(|| {
context.client
.state_at(&BlockId::number(1))
.expect("state_at failed for block#1")
.inspect_state(|| {
match self.block_type {
BlockType::RandomTransfersKeepAlive => {
// should be 5 per signed extrinsic + 1 per unsigned
@@ -37,11 +37,13 @@ pub trait InspectState<H: Hasher, B: Backend<H>> {
///
/// Self will be set as read-only externalities and inspection
/// closure will be run against it.
fn inspect_with<F: FnOnce()>(&self, f: F);
///
/// Returns the result of the closure.
fn inspect_state<F: FnOnce() -> R, R>(&self, f: F) -> R;
}
impl<H: Hasher, B: Backend<H>> InspectState<H, B> for B {
fn inspect_with<F: FnOnce()>(&self, f: F) {
fn inspect_state<F: FnOnce() -> R, R>(&self, f: F) -> R {
ReadOnlyExternalities::from(self).execute_with(f)
}
}