From 284aad501cdf0900f6caaecf99a882021e6df347 Mon Sep 17 00:00:00 2001 From: John Lewis Date: Fri, 6 Sep 2024 15:51:21 -0500 Subject: [PATCH] feat: add `from_err()` method to `Report` --- src/eyreish/error.rs | 8 ++++++++ src/eyreish/into_diagnostic.rs | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/eyreish/error.rs b/src/eyreish/error.rs index 94e4128..cbb4aee 100644 --- a/src/eyreish/error.rs +++ b/src/eyreish/error.rs @@ -425,6 +425,14 @@ impl Report { } .into() } + + /// Construct a [`Report`] directly from an error-like type + pub fn from_err(err: E) -> Self + where + E: std::error::Error + Send + Sync + 'static, + { + super::DiagnosticError(Box::new(err)).into() + } } impl From for Report diff --git a/src/eyreish/into_diagnostic.rs b/src/eyreish/into_diagnostic.rs index 6480013..f862ac6 100644 --- a/src/eyreish/into_diagnostic.rs +++ b/src/eyreish/into_diagnostic.rs @@ -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); +pub(crate) struct DiagnosticError(pub(crate) Box); impl Diagnostic for DiagnosticError {} /**