From c1da4a0d2744e94e409cabeafe911e99598d4ee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Sat, 21 Aug 2021 22:55:45 -0700 Subject: [PATCH] feat(into_diagnostic): .into_diagnostic() is now generic across any impl fmt::Display instead of expecting a `dyn` --- src/utils.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index 65adab6..f80ff0e 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -30,14 +30,17 @@ impl Diagnostic for DiagnosticError { } } +/** +Convenience trait that adds a `.into_diagnostic()` method that converts a type to a `Result`. +*/ pub trait IntoDiagnostic { /// Converts [Result]-like types that return regular errors into a /// `Result` that returns a [Diagnostic]. - fn into_diagnostic(self, code: &(dyn fmt::Display)) -> Result; + fn into_diagnostic(self, code: impl fmt::Display) -> Result; } impl IntoDiagnostic for Result { - fn into_diagnostic(self, code: &(dyn fmt::Display)) -> Result { + fn into_diagnostic(self, code: impl fmt::Display) -> Result { self.map_err(|e| DiagnosticError { error: Box::new(e), code: format!("{}", code),