use std::error::Error;
use crate::error::RetryableStorageError;
use crate::key::KeyError;
#[derive(Debug, thiserror::Error)]
pub enum FlatError<E> {
#[error("store content does not match this layout version")]
Foreign,
#[error("store content is malformed")]
Corrupt,
#[error(transparent)]
Key(KeyError),
#[error("{0}")]
Engine(#[from] E),
}
impl<E: std::fmt::Debug + PartialEq> PartialEq for FlatError<E> {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Foreign, Self::Foreign) | (Self::Corrupt, Self::Corrupt) => true,
(Self::Key(a), Self::Key(b)) => a == b,
(Self::Engine(a), Self::Engine(b)) => a == b,
_ => false,
}
}
}
impl<E: Error + RetryableStorageError> RetryableStorageError for FlatError<E> {
fn is_retryable(&self) -> bool {
match self {
FlatError::Engine(e) => e.is_retryable(),
_ => false,
}
}
}