From a58b84ce956363616c30c9d790683c369a53b5f6 Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang <93241502+yhchiang-sol@users.noreply.github.com> Date: Tue, 11 Jul 2023 00:33:36 +0800 Subject: [PATCH] [TieredStorage] TieredReadableAccount::data() (#32433) #### Problem While TieredReadableAccount implements ReadableAccount that already includes `fn data(&self) -> &'a [u8]`, a `data()` function that directly under TieredReadableAccount is still needed in order to correctly link the lifetime of the returned value and its member account_block. Otherwise, cargo will complain lifetime may not live long enough. #### Summary of Changes This PR adds TieredReadableAccount::data() that directly links the lifetime of its account_block to the returned value. --- runtime/src/tiered_storage/readable.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/runtime/src/tiered_storage/readable.rs b/runtime/src/tiered_storage/readable.rs index cf2b968f7..8a9e223e8 100644 --- a/runtime/src/tiered_storage/readable.rs +++ b/runtime/src/tiered_storage/readable.rs @@ -41,6 +41,11 @@ impl<'a, M: TieredAccountMeta> TieredReadableAccount<'a, M> { pub fn write_version(&self) -> Option { self.meta.write_version(self.account_block) } + + /// Returns the data associated to this account. + pub fn data(&self) -> &'a [u8] { + self.meta.account_data(self.account_block) + } } impl<'a, M: TieredAccountMeta> ReadableAccount for TieredReadableAccount<'a, M> { @@ -73,6 +78,6 @@ impl<'a, M: TieredAccountMeta> ReadableAccount for TieredReadableAccount<'a, M> /// Returns the data associated to this account. fn data(&self) -> &'a [u8] { - self.meta.account_data(self.account_block) + self.data() } }