casper_types/transfer/
error.rsuse core::{
array::TryFromSliceError,
fmt::{self, Debug, Display, Formatter},
};
#[cfg(feature = "std")]
use std::error::Error as StdError;
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum TransferFromStrError {
InvalidPrefix,
Hex(base16::DecodeError),
Length(TryFromSliceError),
}
impl From<base16::DecodeError> for TransferFromStrError {
fn from(error: base16::DecodeError) -> Self {
TransferFromStrError::Hex(error)
}
}
impl From<TryFromSliceError> for TransferFromStrError {
fn from(error: TryFromSliceError) -> Self {
TransferFromStrError::Length(error)
}
}
impl Display for TransferFromStrError {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
match self {
TransferFromStrError::InvalidPrefix => {
write!(formatter, "transfer addr prefix is invalid",)
}
TransferFromStrError::Hex(error) => {
write!(
formatter,
"failed to decode address portion of transfer addr from hex: {}",
error
)
}
TransferFromStrError::Length(error) => write!(
formatter,
"address portion of transfer addr is wrong length: {}",
error
),
}
}
}
#[cfg(feature = "std")]
impl StdError for TransferFromStrError {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
match self {
TransferFromStrError::InvalidPrefix => None,
TransferFromStrError::Hex(error) => Some(error),
TransferFromStrError::Length(error) => Some(error),
}
}
}