pub enum ChainHashError {
HashStringSize,
HashSize,
HashToString(std::fmt::Error),
HexDecode(hex::FromHexError),
}
impl std::fmt::Display for ChainHashError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self {
ChainHashError::HashStringSize => write!(
f,
"Max hash string length is {} bytes",
super::constants::MAX_HASH_STRING_SIZE
),
ChainHashError::HashSize => write!(
f,
"Max hash length is {} bytes",
super::constants::HASH_SIZE
),
ChainHashError::HashToString(e) => {
write!(f, "Invalid hex to string conversion, error: {}", e)
}
ChainHashError::HexDecode(e) => write!(f, "Error decoding hex, error: {}", e),
}
}
}
impl std::fmt::Debug for ChainHashError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self {
ChainHashError::HashStringSize => write!(
f,
"ChainHashError(max hash string length is {} bytes)",
super::constants::HASH_SIZE
),
ChainHashError::HashSize => write!(
f,
"ChainHashError(Max hash length is {} bytes)",
super::constants::HASH_SIZE
),
ChainHashError::HashToString(e) => write!(
f,
"ChainHashError(Invalid hex to string conversion, error: {})",
e
),
ChainHashError::HexDecode(e) => {
write!(f, "ChainHashError(Error decoding hex, error: {})", e)
}
}
}
}