From 50238d75a2db2dccbe2ae2cba78d0dd6eac4ef2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Thu, 5 Aug 2021 12:37:11 -0700 Subject: [PATCH] feat(protocol): Make usafe of ? and return types with Diagnostics more ergonomic --- src/protocol.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/protocol.rs b/src/protocol.rs index 61b8a82..a26f2a5 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -12,7 +12,7 @@ use crate::MietteError; Adds rich metadata to your Error that can be used by [DiagnosticReporter] to print really nice and human-friendly error messages. */ -pub trait Diagnostic: std::error::Error + Send + Sync { +pub trait Diagnostic: std::error::Error { /// Unique diagnostic code that can be used to look up more information /// about this Diagnostic. Ideally also globally unique, and documented in /// the toplevel crate's documentation for easy searching. Rust path @@ -37,6 +37,14 @@ pub trait Diagnostic: std::error::Error + Send + Sync { } } +impl std::error::Error for Box {} + +impl From for Box { + fn from(diag: T) -> Self { + Box::new(diag) + } +} + /** Protocol for [Diagnostic] handlers, which are responsible for actually printing out Diagnostics.