use std::boxed::Box;
use std::convert::Into;
use std::error;
use std::fmt;
use std::marker::{Send, Sync};
#[derive(Debug)]
pub struct Error {
kind: ErrorKind,
error: Box<error::Error + Send + Sync>,
}
#[derive(Debug, PartialEq)]
pub enum ErrorKind {
InvalidArg,
DecompFailure,
AlgebraFailure,
DivByZero,
ScalarConversionFailure,
InvalidPermutation
}
impl Error {
pub fn new<E>(kind: ErrorKind, error: E) -> Error
where E: Into<Box<error::Error + Send + Sync>>
{
Error {
kind: kind,
error: error.into(),
}
}
pub fn kind(&self) -> &ErrorKind {
&self.kind
}
}
impl error::Error for Error {
fn description(&self) -> &str {
self.error.description()
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.error.fmt(f)
}
}