From 93d3bd118a072c35aa761f0ec74317166ec08113 Mon Sep 17 00:00:00 2001 From: John Lewis Date: Sat, 7 Sep 2024 01:56:01 -0500 Subject: [PATCH] feat(Report): add `from_err()` method to `Report` (#403) --- 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 {} /**