use std::fmt;
use std::io;
use crate::errors::{DBIOError, RainDBError};
use crate::versioning::errors::WriteError;
pub(crate) type CompactionWorkerResult<T> = Result<T, CompactionWorkerError>;
#[derive(Clone, Debug, PartialEq)]
pub enum CompactionWorkerError {
IO(DBIOError),
WriteTable(Box<RainDBError>),
VersionManifestError(WriteError),
UnexpectedState(String),
}
impl std::error::Error for CompactionWorkerError {}
impl fmt::Display for CompactionWorkerError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CompactionWorkerError::IO(base_err) => write!(f, "{}", base_err),
CompactionWorkerError::WriteTable(base_err) => write!(f, "{}", base_err),
CompactionWorkerError::VersionManifestError(base_err) => write!(f, "{}", base_err),
CompactionWorkerError::UnexpectedState(reason) => write!(f, "{}", reason),
}
}
}
impl From<io::Error> for CompactionWorkerError {
fn from(err: io::Error) -> Self {
CompactionWorkerError::IO(err.into())
}
}
impl From<WriteError> for CompactionWorkerError {
fn from(err: WriteError) -> Self {
CompactionWorkerError::VersionManifestError(err)
}
}