how.rs/src/explain.rs

25 lines
589 B
Rust

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<T, E> Sealed for Result<T, E> where Result<T, E>: IntoResultHow {}
impl<T, E> Explain for Result<T, E>
where
Result<T, E>: IntoResultHow,
{
type Output = Result<<Self as IntoResultHow>::T, How>;
#[inline(always)]
fn context(self, context: impl IntoContext) -> Self::Output {
self.into_result_how().map_err(|e| e.context(context))
}
}