#[cfg(feature = "enabled")]
pub mod assert;
#[cfg(feature = "enabled")]
#[cfg(feature = "error_typed")]
pub mod typed;
#[cfg(feature = "enabled")]
#[cfg(feature = "error_untyped")]
pub mod untyped;
mod private {
pub use core::error::Error as ErrorTrait;
pub trait ErrWith<ReportErr, ReportOk, E> {
fn err_with<F>(self, f: F) -> core::result::Result<ReportOk, (ReportErr, E)>
where
F: FnOnce() -> ReportErr;
fn err_with_report(self, report: &ReportErr) -> core::result::Result<ReportOk, (ReportErr, E)>
where
ReportErr: Clone;
}
impl<ReportErr, ReportOk, E, IntoError> ErrWith<ReportErr, ReportOk, E> for core::result::Result<ReportOk, IntoError>
where
IntoError: Into<E>,
{
#[inline]
fn err_with<F>(self, f: F) -> core::result::Result<ReportOk, (ReportErr, E)>
where
F: FnOnce() -> ReportErr,
{
self.map_err(|error| (f(), error.into()))
}
#[inline(always)]
fn err_with_report(self, report: &ReportErr) -> core::result::Result<ReportOk, (ReportErr, E)>
where
ReportErr: Clone,
Self: Sized,
{
self.map_err(|error| (report.clone(), error.into()))
}
}
pub type ResultWithReport<Report, Error> = Result<Report, (Report, Error)>;
}
#[cfg(feature = "enabled")]
pub use private::{ErrWith, ResultWithReport, ErrorTrait};
#[cfg(feature = "enabled")]
pub use assert::*;