use super::{Local, Mutable, Problem, ProblemConversion, ProblemResultExt, SendSync};
use {
rootcause::{IntoReport, IntoReportCollection},
std::fmt,
};
pub trait ProblemResultExtension<OkT, ErrorT> {
fn in_context<ContextT>(self, context: ContextT) -> Result<OkT, Problem<ContextT, Mutable, SendSync>>
where
ErrorT: IntoReportCollection<SendSync>,
ContextT: fmt::Debug + fmt::Display + Send + Sync;
fn in_context_local<ContextT>(self, context: ContextT) -> Result<OkT, Problem<ContextT, Mutable, Local>>
where
ErrorT: IntoReportCollection<Local>,
ContextT: fmt::Debug + fmt::Display;
fn convert_into<ContextT>(self) -> Result<OkT, Problem<ContextT, Mutable, SendSync>>
where
ErrorT: IntoReport<SendSync>,
ContextT: ProblemConversion<ErrorT::Context, ErrorT::Ownership, SendSync>;
fn convert_into_local<ContextT>(self) -> Result<OkT, Problem<ContextT, Mutable, Local>>
where
ErrorT: IntoReport<Local>,
ContextT: ProblemConversion<ErrorT::Context, ErrorT::Ownership, Local>;
}
impl<OkT, ErrorT> ProblemResultExtension<OkT, ErrorT> for Result<OkT, ErrorT> {
fn in_context<ContextT>(self, context: ContextT) -> Result<OkT, Problem<ContextT, Mutable, SendSync>>
where
ErrorT: IntoReportCollection<SendSync>,
ContextT: fmt::Debug + fmt::Display + Send + Sync,
{
self.context(context)
}
fn in_context_local<ContextT>(self, context: ContextT) -> Result<OkT, Problem<ContextT, Mutable, Local>>
where
ErrorT: IntoReportCollection<Local>,
ContextT: fmt::Debug + fmt::Display,
{
self.local_context(context)
}
fn convert_into<ContextT>(self) -> Result<OkT, Problem<ContextT, Mutable, SendSync>>
where
ErrorT: IntoReport<SendSync>,
ContextT: ProblemConversion<ErrorT::Context, ErrorT::Ownership, SendSync>,
{
self.context_to()
}
fn convert_into_local<ContextT>(self) -> Result<OkT, Problem<ContextT, Mutable, Local>>
where
ErrorT: IntoReport<Local>,
ContextT: ProblemConversion<ErrorT::Context, ErrorT::Ownership, Local>,
{
self.local_context_to()
}
}