#[derive(Debug, Eq, PartialEq, Clone, Copy)]
pub enum ErrorKind {
Unexpected,
IOError,
BadInput,
FormatError,
TensorError,
NotImplemented,
}
#[derive(Debug)]
pub struct Error {
pub kind: ErrorKind,
pub message: String,
pub cause: Option<Box<dyn std::error::Error>>,
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{:?}: {}", self.kind, self.message)?;
if let Some(cause) = self.cause.as_ref() {
write!(f, "\ncaused by: {}", cause)?;
}
Ok(())
}
}
impl<S: Into<String>> From<(ErrorKind, S)> for Error {
fn from((kind, message): (ErrorKind, S)) -> Self {
Self {
kind,
message: message.into(),
cause: None,
}
}
}
impl std::error::Error for Error {}
pub type Result<T> = std::result::Result<T, Error>;