From a1b644cffa9d6eba32cf51501ef2402b4a843c92 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Fri, 29 Dec 2023 20:53:53 -0700 Subject: [PATCH] Implement Display trait for `DecodingError` --- zcash_client_backend/src/keys.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/zcash_client_backend/src/keys.rs b/zcash_client_backend/src/keys.rs index a850b618d..ef9c676e6 100644 --- a/zcash_client_backend/src/keys.rs +++ b/zcash_client_backend/src/keys.rs @@ -117,6 +117,30 @@ pub enum DecodingError { KeyDataInvalid(Typecode), } +#[cfg(feature = "unstable")] +impl std::fmt::Display for DecodingError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + DecodingError::ReadError(s) => write!(f, "Read error: {}", s), + DecodingError::EraInvalid => write!(f, "Invalid era"), + DecodingError::EraMismatch(e) => write!(f, "Era mismatch: actual {:?}", e), + DecodingError::TypecodeInvalid => write!(f, "Invalid typecode"), + DecodingError::LengthInvalid => write!(f, "Invalid length"), + DecodingError::LengthMismatch(t, l) => { + write!( + f, + "Length mismatch: received {} bytes for typecode {:?}", + l, t + ) + } + DecodingError::InsufficientData(t) => { + write!(f, "Insufficient data for typecode {:?}", t) + } + DecodingError::KeyDataInvalid(t) => write!(f, "Invalid key data for typecode {:?}", t), + } + } +} + #[cfg(feature = "unstable")] impl Era { /// Returns the unique identifier for the era.