Skip to content

Commit

Permalink
feat(protocol): Make usafe of ? and return types with Diagnostics mor…
Browse files Browse the repository at this point in the history
…e ergonomic
  • Loading branch information
zkat committed Aug 5, 2021
1 parent e955321 commit 50238d7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,6 +37,14 @@ pub trait Diagnostic: std::error::Error + Send + Sync {
}
}

impl std::error::Error for Box<dyn Diagnostic> {}

impl<T: Diagnostic + 'static> From<T> for Box<dyn Diagnostic> {
fn from(diag: T) -> Self {
Box::new(diag)
}
}

/**
Protocol for [Diagnostic] handlers, which are responsible for actually printing out Diagnostics.
Expand Down

0 comments on commit 50238d7

Please sign in to comment.