mirror of https://github.com/zkat/miette.git
feat(into_diagnostic): .into_diagnostic() is now generic across any impl fmt::Display instead of expecting a `dyn`
This commit is contained in:
parent
5c077d30a4
commit
c1da4a0d27
|
|
@ -30,14 +30,17 @@ impl Diagnostic for DiagnosticError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Convenience trait that adds a `.into_diagnostic()` method that converts a type to a `Result<T, DiagnosticError>`.
|
||||||
|
*/
|
||||||
pub trait IntoDiagnostic<T, E> {
|
pub trait IntoDiagnostic<T, E> {
|
||||||
/// Converts [Result]-like types that return regular errors into a
|
/// Converts [Result]-like types that return regular errors into a
|
||||||
/// `Result` that returns a [Diagnostic].
|
/// `Result` that returns a [Diagnostic].
|
||||||
fn into_diagnostic(self, code: &(dyn fmt::Display)) -> Result<T, DiagnosticError>;
|
fn into_diagnostic(self, code: impl fmt::Display) -> Result<T, DiagnosticError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, E: std::error::Error + Send + Sync + 'static> IntoDiagnostic<T, E> for Result<T, E> {
|
impl<T, E: std::error::Error + Send + Sync + 'static> IntoDiagnostic<T, E> for Result<T, E> {
|
||||||
fn into_diagnostic(self, code: &(dyn fmt::Display)) -> Result<T, DiagnosticError> {
|
fn into_diagnostic(self, code: impl fmt::Display) -> Result<T, DiagnosticError> {
|
||||||
self.map_err(|e| DiagnosticError {
|
self.map_err(|e| DiagnosticError {
|
||||||
error: Box::new(e),
|
error: Box::new(e),
|
||||||
code: format!("{}", code),
|
code: format!("{}", code),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue