use crate::{CapturedDiagnostic, Diagnostic, DiagnosticMetadata, Reporter};
use std::error::Error;
pub type DiagnosticResult<T> = std::result::Result<T, Box<Diagnostic>>;
pub type CapturedDiagnosticResult<T> = std::result::Result<T, Box<CapturedDiagnostic>>;
pub trait ResultDiagnosticExt<T> {
fn into_diagnostic(self, reporter: &Reporter) -> DiagnosticResult<T>;
fn into_captured_diagnostic(self, reporter: &Reporter) -> CapturedDiagnosticResult<T>;
}
impl<T, E> ResultDiagnosticExt<T> for std::result::Result<T, E>
where
E: Error + DiagnosticMetadata + 'static,
{
fn into_diagnostic(self, reporter: &Reporter) -> DiagnosticResult<T> {
self.map_err(|error| Box::new(reporter.diagnostic_from_typed_error(&error)))
}
fn into_captured_diagnostic(self, reporter: &Reporter) -> CapturedDiagnosticResult<T> {
self.map_err(|error| {
Box::new(reporter.capture(reporter.diagnostic_from_typed_error(&error)))
})
}
}