postal_code/
error.rs

1crate::ix!();
2
3/// Error type for postal code operations.
4#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5pub enum PostalCodeConstructionError {
6    /// The provided country is not supported by this library.
7    UnsupportedCountry {
8        /// Provided country that is not supported.
9        attempted_country: Country,
10    },
11    /// The provided postal code format is invalid for the specified country.
12    InvalidFormat {
13        /// Provided postal code that failed validation.
14        attempted_code: String,
15        /// Country code attempted.
16        attempted_country: Option<Country>,
17    },
18    /// Internal error: regex initialization failed.
19    RegexInitializationError {
20        /// The country whose regex failed initialization.
21        country: Country,
22    },
23}
24
25impl From<derive_builder::UninitializedFieldError> for PostalCodeConstructionError {
26    fn from(_e: derive_builder::UninitializedFieldError) -> Self {
27        // Convert to a suitable error, for example:
28        PostalCodeConstructionError::InvalidFormat {
29            attempted_code: "<unset>".to_string(),
30            attempted_country: None,
31        }
32    }
33}