Skip to main content

geonative_proj/
error.rs

1//! Projection-engine error type.
2
3use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, ProjError>;
6
7#[derive(Debug, Error)]
8pub enum ProjError {
9    #[error("unsupported EPSG code: {0} (v0.1 supports 4326, 3857, 7844, 32601–32760, 7846–7859)")]
10    UnsupportedEpsg(u32),
11
12    #[error("unsupported CRS form: {0}")]
13    UnsupportedCrs(String),
14
15    #[error("coordinate out of projection domain: ({x}, {y})")]
16    OutOfDomain { x: f64, y: f64 },
17}
18
19impl From<ProjError> for geonative_core::Error {
20    fn from(e: ProjError) -> Self {
21        match e {
22            ProjError::UnsupportedEpsg(_) | ProjError::UnsupportedCrs(_) => {
23                geonative_core::Error::unsupported(e.to_string())
24            }
25            ProjError::OutOfDomain { .. } => geonative_core::Error::malformed(e.to_string()),
26        }
27    }
28}