use crate::{ErrReport, EyreContext};
use core::fmt::{Debug, Display};
#[cfg(feature = "std")]
use crate::StdError;
pub struct Adhoc;
pub trait AdhocKind: Sized {
#[inline]
fn eyre_kind(&self) -> Adhoc {
Adhoc
}
}
impl<T> AdhocKind for &T where T: ?Sized + Display + Debug + Send + Sync + 'static {}
impl Adhoc {
pub fn new<M, C: EyreContext>(self, message: M) -> ErrReport<C>
where
M: Display + Debug + Send + Sync + 'static,
{
ErrReport::from_adhoc(message)
}
}
pub struct Trait;
pub trait TraitKind: Sized {
#[inline]
fn eyre_kind(&self) -> Trait {
Trait
}
}
impl<E> TraitKind for E where E: Into<ErrReport> {}
impl Trait {
pub fn new<E>(self, error: E) -> ErrReport
where
E: Into<ErrReport>,
{
error.into()
}
}
#[cfg(feature = "std")]
pub struct Boxed;
#[cfg(feature = "std")]
pub trait BoxedKind: Sized {
#[inline]
fn eyre_kind(&self) -> Boxed {
Boxed
}
}
#[cfg(feature = "std")]
impl BoxedKind for Box<dyn StdError + Send + Sync> {}
#[cfg(feature = "std")]
impl Boxed {
pub fn new<C: EyreContext>(self, error: Box<dyn StdError + Send + Sync>) -> ErrReport<C> {
ErrReport::from_boxed(error)
}
}