use crate::{How, IntoContext, IntoResultHow}; crate::seal!(pub(crate) private::Sealed); pub trait Explain: Sealed { type Output; #[must_use] fn context(self, context: impl IntoContext) -> Self::Output; } impl Sealed for Result where Result: IntoResultHow {} impl Sealed for Option where Option: IntoResultHow {} impl Explain for Result where Result: IntoResultHow, { type Output = Result<::T, How>; #[inline(always)] fn context(self, context: impl IntoContext) -> Self::Output { self.into_result_how().map_err(#[inline(never)] move |e| e.context(context)) } } impl Explain for Option where Option: IntoResultHow, { type Output = Result<::T, How>; #[inline(always)] fn context(self, context: impl IntoContext) -> Self::Output { // TODO: maybe add a toggle for the extra "Option::None" context //Err(How::new(context)) self.into_result_how().map_err(#[inline(never)] move |e| e.context(context)) } }