Skip to content

Commit

Permalink
implement Display and Error for DecodeError
Browse files Browse the repository at this point in the history
  • Loading branch information
noib3 committed Jan 2, 2024
1 parent b50cf80 commit adc969f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/encoded_replica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@ pub enum DecodeError {
InvalidData,
}

impl core::fmt::Display for DecodeError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
DecodeError::ChecksumFailed => f.write_str("checksum failed"),

DecodeError::DifferentProtocol { encoded_on, decoding_on } => {
write!(
f,
"different protocol: encoded on {:?}, decoding on {:?}",
encoded_on, decoding_on
)
},

DecodeError::InvalidData => f.write_str("invalid data"),
}
}
}

impl std::error::Error for DecodeError {}

#[inline(always)]
pub(crate) fn checksum(bytes: &[u8]) -> Checksum {
Box::new(checksum_array(bytes))
Expand Down

0 comments on commit adc969f

Please sign in to comment.