use core::fmt;
pub type BoxError = alloc::boxed::Box<dyn core::error::Error + Send + Sync>;
pub type CloneableError = alloc::sync::Arc<dyn core::error::Error + Send + Sync>;
#[derive(Debug, Clone)]
pub struct Error {
inner: CloneableError,
}
impl Error {
pub fn new(error: impl Into<BoxError>) -> Self {
Self {
inner: CloneableError::from(error.into()),
}
}
pub fn into_inner(self) -> CloneableError {
self.inner
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.inner.fmt(f)
}
}
impl core::error::Error for Error {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
Some(&*self.inner)
}
}