geonative_shapefile/
error.rs1use thiserror::Error;
8
9pub type Result<T> = std::result::Result<T, ShpError>;
10
11#[derive(Debug, Error)]
12pub enum ShpError {
13 #[error("I/O error: {0}")]
14 Io(#[from] std::io::Error),
15
16 #[error("malformed input: {0}")]
17 Malformed(String),
18
19 #[error("unsupported feature: {0}")]
20 Unsupported(String),
21
22 #[error("missing required file: {0}")]
23 MissingFile(String),
24
25 #[error("schema mismatch: {0}")]
26 Schema(String),
27}
28
29impl ShpError {
30 pub fn malformed(msg: impl Into<String>) -> Self {
31 Self::Malformed(msg.into())
32 }
33
34 pub fn unsupported(msg: impl Into<String>) -> Self {
35 Self::Unsupported(msg.into())
36 }
37}
38
39impl From<ShpError> for geonative_core::Error {
40 fn from(e: ShpError) -> Self {
41 match e {
42 ShpError::Io(io) => geonative_core::Error::Io(io),
43 ShpError::Unsupported(s) => geonative_core::Error::unsupported(s),
44 other => geonative_core::Error::malformed(other.to_string()),
45 }
46 }
47}