feat(protocol): Make usafe of ? and return types with Diagnostics more ergonomic

This commit is contained in:
Kat Marchán 2021-08-05 12:37:11 -07:00
parent e955321cbd
commit 50238d75a2
No known key found for this signature in database
GPG Key ID: AEB529C08A3C7E9E
1 changed files with 9 additions and 1 deletions

View File

@ -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<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.