feat(chain, file_store): add is_empty method to PersistBackend trait
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user