use failure::{self, Backtrace, Context, Fail};
use std::fmt::{self, Display};
use std::result;
pub type Result<T> = result::Result<T, failure::Error>;
#[derive(Debug, Fail)]
pub enum ErrorKind {
#[fail(display = "Generic error.")]
Other,
}
#[derive(Debug)]
pub struct Error {
inner: Context<ErrorKind>,
}
impl Error {
pub fn kind(&self) -> &ErrorKind {
&*self.inner.get_context()
}
}
impl Fail for Error {
fn cause(&self) -> Option<&dyn Fail> {
self.inner.cause()
}
fn backtrace(&self) -> Option<&Backtrace> {
self.inner.backtrace()
}
}
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Display::fmt(&self.inner, f)
}
}
impl From<ErrorKind> for Error {
fn from(kind: ErrorKind) -> Error {
let inner = Context::new(kind);
Error { inner }
}
}
impl From<Context<ErrorKind>> for Error {
fn from(inner: Context<ErrorKind>) -> Error {
Error { inner }
}
}