Implement std::error::Error for all rejections (#153)

This commit is contained in:
David Pedersen
2021-08-07 21:03:04 +02:00
committed by GitHub
parent a38d5c3592
commit 6a82dd75ea
3 changed files with 121 additions and 10 deletions
+40
View File
@@ -58,6 +58,14 @@ macro_rules! define_rejection {
res
}
}
impl std::fmt::Display for $name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", $body)
}
}
impl std::error::Error for $name {}
};
(
@@ -90,6 +98,18 @@ macro_rules! define_rejection {
res
}
}
impl std::fmt::Display for $name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", $body)
}
}
impl std::error::Error for $name {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(&self.0)
}
}
};
}
@@ -132,5 +152,25 @@ macro_rules! composite_rejection {
}
}
)+
impl std::fmt::Display for $name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
$(
Self::$variant(inner) => write!(f, "{}", inner),
)+
}
}
}
impl std::error::Error for $name {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
$(
Self::$variant(inner) => Some(inner),
)+
}
}
}
};
}