use std::fmt;
#[derive(Debug, Clone, PartialEq)]
pub enum ValidationError {
Empty,
InvalidCountryCode,
InvalidLength { expected: usize, found: usize },
InvalidCharacter { character: char, position: usize },
InvalidChecksum,
}
impl fmt::Display for ValidationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Empty => write!(f, "IBAN is empty"),
Self::InvalidCountryCode => write!(f, "IBAN contains an unknown country code"),
Self::InvalidLength { expected, found } => {
write!(
f,
"IBAN has invalid length: expected {} characters, found {}",
expected, found
)
}
Self::InvalidCharacter { character, position } => {
write!(f, "Invalid character '{}' at position {}", character, position)
}
Self::InvalidChecksum => write!(f, "IBAN checksum is invalid"),
}
}
}
impl std::error::Error for ValidationError {}