reverse-geocoder-cn 0.1.0

离线为中国的区县进行逆地理编码;Offline reverse geocoding for Chinese province, city and county boundaries
Documentation
//! Error types returned by the library and data builder.

/// Errors returned while opening or decoding a local binary data file.
#[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)
    }
}

/// Errors returned while converting source GeoJSON into a binary data file.
#[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)
    }
}

/// A degree-minute coordinate string could not be parsed.
#[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 {}