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

This commit is contained in:
志宇 committed 2023-11-16 07:01:56 +08:00
1 parent 5998a22819
commit 7d5f31f6cc
2 files changed
+34

No files matched your search

+13
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)
}
}