rust_persian_tools/sheba/
errors.rs

1use std::num::ParseIntError;
2
3use thiserror::Error;
4
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6#[derive(Error, Clone, Copy, Debug, Hash, PartialEq, Eq)]
7pub enum ShebaValidationError {
8    #[error("The input is empty.")]
9    Empty,
10
11    #[error("The input does not start with 'IR'.")]
12    NotStartedWithIR,
13
14    #[error("There is an invalid digit in the input.")]
15    InvalidDigit,
16
17    #[error("Input length is invalid: {0:?}")]
18    InvalidLength(usize),
19
20    #[error("Input checksum is invalid.")]
21    InvalidChecksum,
22
23    #[error("Bank information not found.")]
24    BankNotFound,
25
26    #[error("You should not see this! Please create an issue on our GitHub repository.")]
27    InternalError,
28}
29
30impl From<ParseIntError> for ShebaValidationError {
31    fn from(_: ParseIntError) -> Self {
32        ShebaValidationError::InvalidDigit
33    }
34}