ph_mobile_network/
errors.rs

1use std::error::Error;
2use std::fmt;
3
4#[derive(Debug)]
5pub enum MobileNetworkError {
6    InvalidLength,
7    NonNumeric,
8    UnrecognizedPrefix(String),
9    RegexError(String), // To handle regex compilation errors
10    MutexError(String), // To handle mutex lock errors
11}
12
13impl fmt::Display for MobileNetworkError {
14    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15        match self {
16            MobileNetworkError::InvalidLength => write!(
17                f,
18                "Invalid phone number length. Expected exactly 11 digits."
19            ),
20            MobileNetworkError::NonNumeric => {
21                write!(f, "Mobile number contains non-numeric characters.")
22            }
23            MobileNetworkError::UnrecognizedPrefix(text) => {
24                write!(f, "Unrecognized mobile number prefix: {}", text)
25            }
26            MobileNetworkError::RegexError(text) => write!(f, "Regex error {}", text),
27            MobileNetworkError::MutexError(text) => write!(f, "Mutex lock error {}", text),
28        }
29    }
30}
31
32impl Error for MobileNetworkError {}