use std::{fmt, error};
#[derive(Debug, Copy, Clone)]
pub enum Error {
NotInitialized(&'static str),
AllocFailed(&'static str),
BadParam(&'static str),
InternalError(&'static str),
InvalidValue(&'static str),
ArchMismatch(&'static str),
MappingError(&'static str),
ExecutionFailed(&'static str),
NotSupported(&'static str),
LicenseError(&'static str),
Unknown(&'static str),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::NotInitialized(ref err) => write!(f, "{:?}", err),
Error::AllocFailed(ref err) => write!(f, "{:?}", err),
Error::BadParam(ref err) => write!(f, "{:?}", err),
Error::InternalError(ref err) => write!(f, "{:?}", err),
Error::InvalidValue(ref err) => write!(f, "{:?}", err),
Error::ArchMismatch(ref err) => write!(f, "{:?}", err),
Error::MappingError(ref err) => write!(f, "{:?}", err),
Error::ExecutionFailed(ref err) => write!(f, "{:?}", err),
Error::NotSupported(ref err) => write!(f, "{:?}", err),
Error::LicenseError(ref err) => write!(f, "{:?}", err),
Error::Unknown(ref err) => write!(f, "{:?}", err),
}
}
}
impl error::Error for Error {
fn description(&self) -> &str {
match *self {
Error::NotInitialized(ref err) => err,
Error::AllocFailed(ref err) => err,
Error::BadParam(ref err) => err,
Error::InternalError(ref err) => err,
Error::InvalidValue(ref err) => err,
Error::ArchMismatch(ref err) => err,
Error::MappingError(ref err) => err,
Error::ExecutionFailed(ref err) => err,
Error::NotSupported(ref err) => err,
Error::LicenseError(ref err) => err,
Error::Unknown(ref err) => err,
}
}
fn cause(&self) -> Option<&error::Error> {
match *self {
Error::NotInitialized(_) => None,
Error::AllocFailed(_) => None,
Error::BadParam(_) => None,
Error::InternalError(_) => None,
Error::InvalidValue(_) => None,
Error::ArchMismatch(_) => None,
Error::MappingError(_) => None,
Error::ExecutionFailed(_) => None,
Error::NotSupported(_) => None,
Error::LicenseError(_) => None,
Error::Unknown(_) => None,
}
}
}