use std::error::Error as StdError;
use std::fmt;
use std::ops::Deref;
use std::result;
#[derive(Debug)]
pub struct Error {
inner: anyhow::Error,
}
impl Error {
pub fn new<E>(error: E) -> Self
where
E: StdError + Send + Sync + 'static,
{
Self {
inner: anyhow::Error::new(error),
}
}
pub fn msg<M>(message: M) -> Self
where
M: fmt::Display + fmt::Debug + Send + Sync + 'static,
{
Self {
inner: anyhow::Error::msg(message),
}
}
}
impl<E> From<E> for Error
where
E: StdError + Send + Sync + 'static,
{
fn from(error: E) -> Self {
Self::new(error)
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.inner, f)
}
}
impl AsRef<dyn StdError + Send + Sync + 'static> for Error {
fn as_ref(&self) -> &(dyn StdError + Send + Sync + 'static) {
self.inner.as_ref()
}
}
impl Deref for Error {
type Target = dyn StdError + Send + Sync + 'static;
fn deref(&self) -> &Self::Target {
self.inner.deref()
}
}
impl From<Error> for Box<dyn StdError + Send + Sync + 'static> {
fn from(error: Error) -> Self {
error.into()
}
}
pub type Result<T> = result::Result<T, Error>;