added: src/kind.rs +46 added 1 + use crate::Error;2 + use std::error::Error as StdError;3 + use std::fmt::{Debug, Display};4 + 5 + #[cfg(backtrace)]6 + use std::backtrace::Backtrace;7 + 8 + pub struct Adhoc;9 + 10 + pub trait AdhocKind: Sized {11 + #[inline]12 + fn anyhow_kind(&self) -> Adhoc {13 + Adhoc14 + }15 + }16 + 17 + impl<T> AdhocKind for &T where T: ?Sized + Display + Debug + Send + Sync + 'static {}18 + 19 + impl Adhoc {20 + pub fn new<M>(self, message: M) -> Error21 + where22 + M: Display + Debug + Send + Sync + 'static,23 + {24 + Error::from_adhoc(message, backtrace!())25 + }26 + }27 + 28 + pub struct Trait;29 + 30 + pub trait TraitKind: Sized {31 + #[inline]32 + fn anyhow_kind(&self) -> Trait {33 + Trait34 + }35 + }36 + 37 + impl<T> TraitKind for T where T: StdError + Send + Sync + 'static {}38 + 39 + impl Trait {40 + pub fn new<E>(self, error: E) -> Error41 + where42 + E: StdError + Send + Sync + 'static,43 + {44 + Error::from_std(error, backtrace!())45 + }46 + }