[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.
This commit is contained in:
Yueh-Hsuan Chiang 2023-07-11 00:33:36 +08:00 committed by GitHub
parent 65e90ab0bc
commit a58b84ce95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -41,6 +41,11 @@ impl<'a, M: TieredAccountMeta> TieredReadableAccount<'a, M> {
pub fn write_version(&self) -> Option<StoredMetaWriteVersion> {
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()
}
}