Skip to content

Commit

Permalink
feat(Report): add from_err() method to Report (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbchron authored Sep 7, 2024
1 parent d6b4558 commit 93d3bd1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/eyreish/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/eyreish/into_diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

/**
Expand Down

0 comments on commit 93d3bd1

Please sign in to comment.