feat(chain, file_store): add is_empty method to PersistBackend trait

This commit is contained in:
志宇
2023-10-26 07:47:29 +08:00
parent 5998a22819
commit 7d5f31f6cc
2 changed files with 34 additions and 0 deletions

View File

@@ -80,6 +80,15 @@ pub trait PersistBackend<C> {
/// Return the aggregate changeset `C` from persistence.
fn load_from_persistence(&mut self) -> Result<C, Self::LoadError>;
/// Returns whether the persistence backend contains no data.
fn is_empty(&mut self) -> Result<bool, Self::LoadError>
where
C: Append,
{
self.load_from_persistence()
.map(|changeset| changeset.is_empty())
}
}
impl<C: Default> PersistBackend<C> for () {
@@ -94,4 +103,8 @@ impl<C: Default> PersistBackend<C> for () {
fn load_from_persistence(&mut self) -> Result<C, Self::LoadError> {
Ok(C::default())
}
fn is_empty(&mut self) -> Result<bool, Self::LoadError> {
Ok(true)
}
}