use std::fmt;
#[derive(Debug)]
pub enum Error {
OutOfJapanRange {
lat: f64,
lon: f64,
},
InvalidData(String),
Io(std::io::Error),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::OutOfJapanRange { lat, lon } => {
write!(
f,
"coordinate ({lat}, {lon}) is outside of Japan's range (lat 20-46, lon 122-154)"
)
}
Error::InvalidData(msg) => write!(f, "invalid data: {msg}"),
Error::Io(e) => write!(f, "I/O error: {e}"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Io(e) => Some(e),
_ => None,
}
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Error::Io(e)
}
}