1use std::fmt;
2
3#[derive(Debug, Clone, PartialEq)]
5pub enum ValidationError {
6 Empty,
8 InvalidCountryCode,
10 InvalidLength { expected: usize, found: usize },
12 InvalidCharacter { character: char, position: usize },
14 InvalidChecksum,
16}
17
18impl fmt::Display for ValidationError {
19 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20 match self {
21 Self::Empty => write!(f, "IBAN is empty"),
22 Self::InvalidCountryCode => write!(f, "IBAN contains an unknown country code"),
23 Self::InvalidLength { expected, found } => {
24 write!(
25 f,
26 "IBAN has invalid length: expected {} characters, found {}",
27 expected, found
28 )
29 }
30 Self::InvalidCharacter { character, position } => {
31 write!(f, "Invalid character '{}' at position {}", character, position)
32 }
33 Self::InvalidChecksum => write!(f, "IBAN checksum is invalid"),
34 }
35 }
36}
37
38impl std::error::Error for ValidationError {}