fix(metadata): Remove deprecated error description

Rust 1.42 deprecates the `description()` method of `std::error::Error`
and provides a blanket implementation suggesting implementation of
`std::fmt::Display` instead. We already implemented `Display` for error
types but in terms of the deprecated `description`. This commit
implements `Display` directly and falls back to the blanket
implementation of `description()`.
This commit is contained in:
James Nugent
2020-03-19 14:07:25 -05:00
committed by GitHub
parent 414a8978b8
commit 61e0429ae8
3 changed files with 7 additions and 23 deletions
+3 -11
View File
@@ -180,15 +180,11 @@ impl InvalidMetadataValue {
impl fmt::Display for InvalidMetadataValue {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.description().fmt(f)
f.write_str("failed to parse metadata value")
}
}
impl Error for InvalidMetadataValue {
fn description(&self) -> &str {
"failed to parse metadata value"
}
}
impl Error for InvalidMetadataValue {}
/// A possible error when converting a `MetadataValue` from a string or byte
/// slice.
@@ -209,8 +205,4 @@ impl fmt::Display for InvalidMetadataValueBytes {
}
}
impl Error for InvalidMetadataValueBytes {
fn description(&self) -> &str {
self.0.description()
}
}
impl Error for InvalidMetadataValueBytes {}
+2 -6
View File
@@ -271,12 +271,8 @@ impl<'a, VE: ValueEncoding> PartialEq<MetadataKey<VE>> for &'a str {
impl fmt::Display for InvalidMetadataKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.description().fmt(f)
f.write_str("invalid gRPC metadata key name")
}
}
impl Error for InvalidMetadataKey {
fn description(&self) -> &str {
"invalid gRPC metadata key name"
}
}
impl Error for InvalidMetadataKey {}
+2 -6
View File
@@ -531,15 +531,11 @@ impl ToStrError {
impl fmt::Display for ToStrError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.description().fmt(f)
f.write_str("failed to convert metadata to a str")
}
}
impl Error for ToStrError {
fn description(&self) -> &str {
"failed to convert metadata to a str"
}
}
impl Error for ToStrError {}
// ===== PartialEq / PartialOrd =====