use crate::Error;
use core::fmt::{Debug, Display};
use crate::StdError;
pub struct MakeDebug;
#[doc(hidden)]
pub trait DebugKind: Sized {
#[inline]
fn wallee_kind(&self) -> MakeDebug {
MakeDebug
}
}
impl<T> DebugKind for &T where T: ?Sized + Display + Debug + Send + Sync + 'static {}
impl MakeDebug {
#[cold]
#[track_caller]
pub fn make<M>(self, message: M) -> Error
where
M: Display + Debug + Send + Sync + 'static,
{
Error::from_debug(message, backtrace!())
}
}
pub struct MakeStd;
#[doc(hidden)]
pub trait StdKind: Sized {
#[inline]
fn wallee_kind(&self) -> MakeStd {
MakeStd
}
}
impl<E> StdKind for E where E: StdError + Send + Sync + 'static {}
impl MakeStd {
#[cold]
#[track_caller]
pub fn make<E>(self, error: E) -> Error
where
E: StdError + Send + Sync + 'static,
{
Error::new(error)
}
}
pub struct MakeError;
#[doc(hidden)]
pub trait ErrorKind: Sized {
#[inline]
fn wallee_kind(&self) -> MakeError {
MakeError
}
}
impl ErrorKind for Error {}
impl MakeError {
#[cold]
#[track_caller]
pub fn make(self, error: Error) -> Error {
error
}
}
pub struct Boxed;
#[doc(hidden)]
pub trait BoxedKind: Sized {
#[inline]
fn wallee_kind(&self) -> Boxed {
Boxed
}
}
impl BoxedKind for Box<dyn StdError + Send + Sync> {}
impl Boxed {
#[cold]
#[track_caller]
pub fn make(self, error: Box<dyn StdError + Send + Sync>) -> Error {
let backtrace = backtrace_if_absent!(&*error);
Error::from_boxed(error, backtrace)
}
}