1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use std::fmt::{self, Display};
#[derive(Debug)]
pub enum ValidationError {
TooLong,
InvalidChar,
InvalidIban,
InvalidCountryCode,
InvalidLength,
InvalidFormat,
CountryCheckFailed,
}
impl std::error::Error for ValidationError {}
impl Display for ValidationError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use ValidationError::*;
let msg = match self {
TooLong => "Input is longer than 34 characters.",
InvalidChar => "Input contains at least one invalid character.",
InvalidIban => "IBAN mod 97 checksum is invalid.",
InvalidCountryCode => "Input doesn't contain a supported country.",
InvalidLength => "Input is invalid length for the detected country.",
InvalidFormat => "IBAN has the wrong format for the detected country.",
CountryCheckFailed => "Failed custom country-specific check.",
};
write!(f, "{}", msg)
}
}