Skip to main content

geonative_geojson/
error.rs

1//! GeoJSON-specific error type.
2
3use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, GeoJsonError>;
6
7#[derive(Debug, Error)]
8pub enum GeoJsonError {
9    #[error("I/O error: {0}")]
10    Io(#[from] std::io::Error),
11
12    #[error("JSON parse error: {0}")]
13    Json(#[from] serde_json::Error),
14
15    #[error("malformed GeoJSON: {0}")]
16    Malformed(String),
17
18    #[error("unsupported GeoJSON feature: {0}")]
19    Unsupported(String),
20}
21
22impl GeoJsonError {
23    pub fn malformed(msg: impl Into<String>) -> Self {
24        Self::Malformed(msg.into())
25    }
26
27    pub fn unsupported(msg: impl Into<String>) -> Self {
28        Self::Unsupported(msg.into())
29    }
30}
31
32impl From<GeoJsonError> for geonative_core::Error {
33    fn from(e: GeoJsonError) -> Self {
34        match e {
35            GeoJsonError::Io(io) => geonative_core::Error::Io(io),
36            GeoJsonError::Unsupported(s) => geonative_core::Error::unsupported(s),
37            other => geonative_core::Error::malformed(other.to_string()),
38        }
39    }
40}