use std::error::Error;
use std::fmt::{Display, Formatter, Result as FormatResult};
use super::InternalError;
use super::InvalidStateError;
#[derive(Debug)]
pub enum AlgorithmError {
InvalidState(InvalidStateError),
Internal(InternalError),
}
impl Error for AlgorithmError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
AlgorithmError::InvalidState(e) => Some(e),
AlgorithmError::Internal(e) => Some(e),
}
}
}
impl Display for AlgorithmError {
fn fmt(&self, f: &mut Formatter) -> FormatResult {
match self {
AlgorithmError::InvalidState(e) => write!(f, "{e}"),
AlgorithmError::Internal(e) => write!(f, "{e}"),
}
}
}
impl From<InvalidStateError> for AlgorithmError {
fn from(err: InvalidStateError) -> Self {
AlgorithmError::InvalidState(err)
}
}
impl From<InternalError> for AlgorithmError {
fn from(err: InternalError) -> Self {
AlgorithmError::Internal(err)
}
}