diff --git a/src/protocol.rs b/src/protocol.rs index d94011a..9acb32d 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -66,35 +66,57 @@ pub trait Diagnostic: std::error::Error { } } -impl std::error::Error for Box { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - (**self).source() - } +macro_rules! forwarding_impl { + ($t:ty) => { + impl std::error::Error for $t { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + (**self).source() + } - fn cause(&self) -> Option<&dyn std::error::Error> { - self.source() - } + fn cause(&self) -> Option<&dyn std::error::Error> { + self.source() + } + } + + impl Diagnostic for $t { + fn code<'a>(&'a self) -> Option> { + (**self).code() + } + + fn severity(&self) -> Option { + (**self).severity() + } + + fn help<'a>(&'a self) -> Option> { + (**self).help() + } + + fn url<'a>(&'a self) -> Option> { + (**self).url() + } + + fn source_code(&self) -> Option<&dyn SourceCode> { + (**self).source_code() + } + + fn labels(&self) -> Option + '_>> { + (**self).labels() + } + + fn related<'a>(&'a self) -> Option + 'a>> { + (**self).related() + } + + fn diagnostic_source(&self) -> Option<&dyn Diagnostic> { + (**self).diagnostic_source() + } + } + }; } -impl From - for Box -{ - fn from(diag: T) -> Self { - Box::new(diag) - } -} - -impl From for Box { - fn from(diag: T) -> Self { - Box::::from(diag) - } -} - -impl From for Box { - fn from(diag: T) -> Self { - Box::::from(diag) - } -} +forwarding_impl!(Box); +forwarding_impl!(Box); +forwarding_impl!(Box); impl From<&str> for Box { fn from(s: &str) -> Self {