digipin/
errors.rs

1// Copyright (c) 2026 Pranam
2// ORCID: https://orcid.org/0009-0007-9316-3616
3//
4// This code is licensed under the Apache License, Version 2.0.
5//
6// You may obtain a copy of the License at
7//
8//     https://www.apache.org/licenses/LICENSE-2.0
9//
10// QR Code:
11// ![QR Code](/ORCID.png)
12// Scan the QR code to access my ORCID profile.
13
14use std::fmt::{self};
15
16/// Errors returned by DIGIPIN operations.
17/// # Variants
18/// - `InvalidLatitude`: Latitude is outside geodetic bounds.
19/// - `InvalidLongitude`: Longitude is outside geodetic bounds.
20/// - `OutsideSupportedTerritory`: Location is outside the DIGIPIN supported territory.
21/// - `InvalidDigipinLength`: DIGIPIN does not conform to required length.
22/// - `InvalidDigipinFormat`: DIGIPIN contains invalid symbols or format.
23#[derive(Debug, Clone, PartialEq)]
24pub enum DigipinError {
25    InvalidLatitude,
26    InvalidLongitude,
27    OutsideSupportedTerritory,
28    InvalidDigipinLength,
29    InvalidDigipinFormat,
30}
31
32/// Implements Display trait for DigipinError to provide human-readable error messages.
33/// # Arguments
34/// - `f`: A mutable reference to a Formatter.
35/// # Returns
36/// - `fmt::Result`: The result of the formatting operation.
37impl fmt::Display for DigipinError {
38    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39        match self {
40            Self::InvalidLatitude => {
41                write!(f, "Latitude is outside geodetic bounds.")
42            }
43            Self::InvalidLongitude => {
44                write!(f, "Longitude is outside geodetic bounds.")
45            }
46            Self::OutsideSupportedTerritory => {
47                write!(f, "Location is outside the DIGIPIN supported territory.")
48            }
49            Self::InvalidDigipinLength => {
50                write!(f, "DIGIPIN does not conform to required length.")
51            }
52            Self::InvalidDigipinFormat => {
53                write!(f, "DIGIPIN contains invalid symbols or format.")
54            }
55        }
56    }
57}
58/// Implements the standard Error trait for DigipinError.
59/// # Note
60/// This allows DigipinError to be used as a standard error type in Rust.
61impl std::error::Error for DigipinError {}