#![allow(clippy::redundant_pub_crate)]
macro_rules! r#trait {
($type:ty) => {
pub trait WrapFailure: crate::private::Sealed {
type Return;
fn wrap_failure_with<D, F>(self, message: F) -> Self::Return
where
D: Display + Send + Sync + 'static,
F: FnOnce() -> D;
fn wrap_failure<D>(self, message: D) -> Self::Return
where
D: Display + Send + Sync + 'static;
fn with_context<D, F>(self, message: F) -> Self::Return
where
D: Display + Send + Sync + 'static,
F: FnOnce() -> D;
fn context<D>(self, message: D) -> Self::Return
where
D: Display + Send + Sync + 'static;
}
};
}
macro_rules! r#impl {
($type:ident) => {
impl<S, M, E> WrapFailure for Outcome<S, M, E>
where
E: $type + Send + Sync + 'static,
{
type Return = Outcome<S, M, Report>;
#[track_caller]
#[inline]
fn wrap_failure_with<D, F>(self, message: F) -> Self::Return
where
D: Display + Send + Sync + 'static,
F: FnOnce() -> D,
{
self.map_failure(|f| Report::new(f).wrap_err(message()))
}
#[track_caller]
#[inline]
fn wrap_failure<D>(self, message: D) -> Self::Return
where
D: Display + Send + Sync + 'static,
{
self.map_failure(|f| Report::new(f).wrap_err(message))
}
#[track_caller]
#[inline]
fn with_context<D, F>(self, message: F) -> Self::Return
where
D: Display + Send + Sync + 'static,
F: FnOnce() -> D,
{
self.wrap_failure_with(message)
}
#[track_caller]
#[inline]
fn context<D>(self, message: D) -> Self::Return
where
D: Display + Send + Sync + 'static,
{
self.wrap_failure(message)
}
}
impl<M, E> WrapFailure for Aberration<M, E>
where
E: $type + Send + Sync + 'static,
{
type Return = Aberration<M, Report>;
#[track_caller]
#[inline]
fn wrap_failure_with<D, F>(self, message: F) -> Self::Return
where
D: Display + Send + Sync + 'static,
F: FnOnce() -> D,
{
self.map_failure(|f| Report::new(f).wrap_err(message()))
}
#[track_caller]
#[inline]
fn wrap_failure<D>(self, message: D) -> Self::Return
where
D: Display + Send + Sync + 'static,
{
self.map_failure(|f| Report::new(f).wrap_err(message))
}
#[track_caller]
#[inline]
fn with_context<D, F>(self, message: F) -> Self::Return
where
D: Display + Send + Sync + 'static,
F: FnOnce() -> D,
{
self.wrap_failure_with(message)
}
#[track_caller]
#[inline]
fn context<D>(self, message: D) -> Self::Return
where
D: Display + Send + Sync + 'static,
{
self.wrap_failure(message)
}
}
};
}
macro_rules! r#use {
(miette) => {
"use outcome::diagnostic::{WrapFailure, Result, Report};"
};
(eyre) => {
"use outcome::report::{WrapFailure, Result, Report};"
};
}
macro_rules! r#result {
($module:ident) => {
#[doc = crate::wrap::r#use!($module)]
#[doc = concat!("[`WrapErr`]:", stringify!($module), "::WrapErr")]
impl<T, E> WrapFailure for Result<T, E>
where
Self: $module::WrapErr<T, E>,
{
type Return = Result<T, $module::Report>;
#[track_caller]
#[inline]
fn wrap_failure_with<D, F>(self, message: F) -> Self::Return
where
D: Display + Send + Sync + 'static,
F: FnOnce() -> D,
{
$module::WrapErr::wrap_err_with(self, message)
}
#[track_caller]
#[inline]
fn wrap_failure<D>(self, message: D) -> Self::Return
where
D: Display + Send + Sync + 'static,
{
$module::WrapErr::wrap_err(self, message)
}
#[track_caller]
#[inline]
fn with_context<D, F>(self, message: F) -> Self::Return
where
D: Display + Send + Sync + 'static,
F: FnOnce() -> D,
{
$module::WrapErr::with_context(self, message)
}
#[track_caller]
#[inline]
fn context<D>(self, message: D) -> Self::Return
where
D: Display + Send + Sync + 'static,
{
$module::WrapErr::context(self, message)
}
}
};
}
pub(crate) use {r#impl, r#result, r#trait, r#use};