#[macro_export]
macro_rules! coercible_errors {
() => {
coercible_errors!(Error);
};
($error: ty) => {
coercible_errors!($error, CoercibleWith, CoercedError, CoercedResult);
};
($error: ty, $coercible_with: ident, $coerced_error: ident, $coerced_result: ident) => {
pub use $crate::{Never, OkResult};
impl From<Never> for $error {
fn from(_: Never) -> $error {
unreachable!()
}
}
pub trait $coercible_with<E>:
Sized + std::marker::Send + std::error::Error + 'static
{
type Into: std::marker::Send
+ std::error::Error
+ 'static
+ From<Self>
+ From<E>
+ $coercible_with<$error>
+ $coercible_with<Never>;
}
impl $coercible_with<$error> for $error {
type Into = $error;
}
impl $coercible_with<Never> for $error {
type Into = $error;
}
impl $coercible_with<$error> for Never {
type Into = $error;
}
impl $coercible_with<Never> for Never {
type Into = Never;
}
pub type $coerced_error<E1, E2> = <E1 as $coercible_with<E2>>::Into;
pub type $coerced_result<T, E1, E2> = std::result::Result<T, $coerced_error<E1, E2>>;
};
}
#[derive(Clone, Debug)]
pub enum Never {}
impl ::std::fmt::Display for Never {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
write!(f, "Never")
}
}
impl std::error::Error for Never {}
pub type OkResult<T> = std::result::Result<T, Never>;
#[cfg(feature = "example_generated")]
pub mod example_generated;
#[cfg(test)]
#[macro_use]
extern crate error_chain;
#[cfg(test)]
mod test;