#[derive(Debug)]
pub enum Error {
Io(std::io::Error),
InvalidData(&'static str),
Decode(bincode::error::DecodeError),
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Io(error) => write!(f, "{error}"),
Self::InvalidData(message) => f.write_str(message),
Self::Decode(error) => write!(f, "cannot decode data: {error}"),
}
}
}
impl std::error::Error for Error {}
impl From<std::io::Error> for Error {
fn from(value: std::io::Error) -> Self {
Self::Io(value)
}
}
#[derive(Debug)]
pub enum BuildError {
Io(std::io::Error),
Json(serde_json::Error),
Encode(bincode::error::EncodeError),
InvalidGeoJson(String),
}
impl std::fmt::Display for BuildError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Io(error) => write!(f, "{error}"),
Self::Json(error) => write!(f, "invalid GeoJSON: {error}"),
Self::Encode(error) => write!(f, "cannot encode data: {error}"),
Self::InvalidGeoJson(message) => f.write_str(message),
}
}
}
impl std::error::Error for BuildError {}
impl From<std::io::Error> for BuildError {
fn from(value: std::io::Error) -> Self {
Self::Io(value)
}
}
impl From<serde_json::Error> for BuildError {
fn from(value: serde_json::Error) -> Self {
Self::Json(value)
}
}
impl From<bincode::error::EncodeError> for BuildError {
fn from(value: bincode::error::EncodeError) -> Self {
Self::Encode(value)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CoordinateParseError(pub(crate) &'static str);
impl std::fmt::Display for CoordinateParseError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.0)
}
}
impl std::error::Error for CoordinateParseError {}