japan_reverse_geocoder/
error.rs1use std::fmt;
2
3#[derive(Debug)]
5pub enum Error {
6 OutOfJapanRange {
8 lat: f64,
10 lon: f64,
12 },
13 InvalidData(String),
15 Io(std::io::Error),
17}
18
19impl fmt::Display for Error {
20 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21 match self {
22 Error::OutOfJapanRange { lat, lon } => {
23 write!(
24 f,
25 "coordinate ({lat}, {lon}) is outside of Japan's range (lat 20-46, lon 122-154)"
26 )
27 }
28 Error::InvalidData(msg) => write!(f, "invalid data: {msg}"),
29 Error::Io(e) => write!(f, "I/O error: {e}"),
30 }
31 }
32}
33
34impl std::error::Error for Error {
35 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
36 match self {
37 Error::Io(e) => Some(e),
38 _ => None,
39 }
40 }
41}
42
43impl From<std::io::Error> for Error {
44 fn from(e: std::io::Error) -> Self {
45 Error::Io(e)
46 }
47}