feat: add `from_err()` method to `Report`

This commit is contained in:
John Lewis 2024-09-06 15:51:21 -05:00
parent d6b4558502
commit 284aad501c
2 changed files with 9 additions and 1 deletions

View File

@ -425,6 +425,14 @@ impl Report {
}
.into()
}
/// Construct a [`Report`] directly from an error-like type
pub fn from_err<E>(err: E) -> Self
where
E: std::error::Error + Send + Sync + 'static,
{
super::DiagnosticError(Box::new(err)).into()
}
}
impl<E> From<E> for Report

View File

@ -6,7 +6,7 @@ use crate::{Diagnostic, Report};
/// Errors. This is intended to be paired with [`IntoDiagnostic`].
#[derive(Debug, Error)]
#[error(transparent)]
struct DiagnosticError(Box<dyn std::error::Error + Send + Sync + 'static>);
pub(crate) struct DiagnosticError(pub(crate) Box<dyn std::error::Error + Send + Sync + 'static>);
impl Diagnostic for DiagnosticError {}
/**