From 2273789d69a1a63118d8476366f96bc91f568982 Mon Sep 17 00:00:00 2001 From: Ryan Lopopolo Date: Sun, 20 Dec 2020 08:40:06 -0800 Subject: [PATCH] Avoid write! macro in fmt::Display impl for DecodeError When writing a constant `&str`, use `fmt::Formatter::write_str`. This makes the intent of writing a static literal more clear and should marginally improve compile times by avoiding instantiating the `write!` macro. --- src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c7c23b03..28905be0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -157,17 +157,17 @@ impl std::error::Error for DecodeError {} impl fmt::Display for DecodeError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::ChecksumMismatch => write!(f, "Checksum mismatch"), - Self::Corrupted => write!(f, "Corrupted input"), - Self::ExpectedConsonant => write!(f, "Expected consonant, got something else"), - Self::ExpectedVowel => write!(f, "Expected vowel, got something else"), + Self::ChecksumMismatch => f.write_str("Checksum mismatch"), + Self::Corrupted => f.write_str("Corrupted input"), + Self::ExpectedConsonant => f.write_str("Expected consonant, got something else"), + Self::ExpectedVowel => f.write_str("Expected vowel, got something else"), Self::InvalidByte(pos) => write!( f, "Encountered byte outside of encoding alphabet at position {}", pos ), - Self::MalformedHeader => write!(f, "Missing required 'x' header"), - Self::MalformedTrailer => write!(f, "Missing required 'x' trailer"), + Self::MalformedHeader => f.write_str("Missing required 'x' header"), + Self::MalformedTrailer => f.write_str("Missing required 'x' trailer"), } } }