Skip to content

Commit

Permalink
fix(metadata): Remove deprecated error description
Browse files Browse the repository at this point in the history
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()`.
  • Loading branch information
jen20 authored Mar 19, 2020
1 parent 414a897 commit 61e0429
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 23 deletions.
14 changes: 3 additions & 11 deletions tonic/src/metadata/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -209,8 +205,4 @@ impl fmt::Display for InvalidMetadataValueBytes {
}
}

impl Error for InvalidMetadataValueBytes {
fn description(&self) -> &str {
self.0.description()
}
}
impl Error for InvalidMetadataValueBytes {}
8 changes: 2 additions & 6 deletions tonic/src/metadata/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
8 changes: 2 additions & 6 deletions tonic/src/metadata/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =====

Expand Down

0 comments on commit 61e0429

Please sign in to comment.