Skip to main content

spatialrust_io/
error.rs

1use thiserror::Error;
2
3use spatialrust_core::SpatialError;
4
5/// IO-specific error type for SpatialRust.
6#[derive(Debug, Error, PartialEq)]
7pub enum IoError {
8    /// Underlying IO failure.
9    #[error("io failure: {0}")]
10    Io(String),
11
12    /// PCD header or payload parsing failed.
13    #[error("pcd parse error: {0}")]
14    PcdParse(String),
15
16    /// Unsupported or invalid PCD encoding.
17    #[error("pcd format error: {0}")]
18    PcdFormat(String),
19
20    /// PLY header or payload parsing failed.
21    #[error("ply parse error: {0}")]
22    PlyParse(String),
23
24    /// Unsupported or invalid PLY encoding.
25    #[error("ply format error: {0}")]
26    PlyFormat(String),
27
28    /// LAS header or payload parsing failed.
29    #[error("las parse error: {0}")]
30    LasParse(String),
31
32    /// Unsupported or invalid LAS encoding.
33    #[error("las format error: {0}")]
34    LasFormat(String),
35
36    /// LAZ compression support is not enabled.
37    #[error("laz format error: {0}")]
38    LazFormat(String),
39
40    /// E57 header or payload parsing failed.
41    #[error("e57 parse error: {0}")]
42    E57Parse(String),
43
44    /// Unsupported or invalid E57 encoding.
45    #[error("e57 format error: {0}")]
46    E57Format(String),
47
48    /// COPC header or payload parsing failed.
49    #[error("copc parse error: {0}")]
50    CopcParse(String),
51
52    /// Unsupported or invalid COPC encoding.
53    #[error("copc format error: {0}")]
54    CopcFormat(String),
55
56    /// Core data model error propagated from `spatialrust-core`.
57    #[error(transparent)]
58    Core(#[from] SpatialError),
59}
60
61impl From<std::io::Error> for IoError {
62    fn from(error: std::io::Error) -> Self {
63        Self::Io(error.to_string())
64    }
65}
66
67#[cfg_attr(not(feature = "io-pcd"), allow(dead_code))]
68pub(crate) fn pcd_parse(message: impl Into<String>) -> IoError {
69    IoError::PcdParse(message.into())
70}
71
72#[cfg_attr(not(feature = "io-pcd"), allow(dead_code))]
73pub(crate) fn pcd_format(message: impl Into<String>) -> IoError {
74    IoError::PcdFormat(message.into())
75}
76
77#[cfg_attr(not(feature = "io-ply"), allow(dead_code))]
78pub(crate) fn ply_parse(message: impl Into<String>) -> IoError {
79    IoError::PlyParse(message.into())
80}
81
82#[cfg_attr(not(feature = "io-ply"), allow(dead_code))]
83pub(crate) fn ply_format(message: impl Into<String>) -> IoError {
84    IoError::PlyFormat(message.into())
85}
86
87#[cfg_attr(not(feature = "io-las"), allow(dead_code))]
88pub(crate) fn las_parse(message: impl Into<String>) -> IoError {
89    IoError::LasParse(message.into())
90}
91
92#[cfg_attr(not(feature = "io-las"), allow(dead_code))]
93pub(crate) fn las_format(message: impl Into<String>) -> IoError {
94    IoError::LasFormat(message.into())
95}
96
97#[allow(dead_code)]
98pub(crate) fn laz_format(message: impl Into<String>) -> IoError {
99    IoError::LazFormat(message.into())
100}
101
102#[cfg_attr(not(feature = "io-e57"), allow(dead_code))]
103pub(crate) fn e57_parse(message: impl Into<String>) -> IoError {
104    IoError::E57Parse(message.into())
105}
106
107#[cfg_attr(not(feature = "io-e57"), allow(dead_code))]
108pub(crate) fn e57_format(message: impl Into<String>) -> IoError {
109    IoError::E57Format(message.into())
110}
111
112#[cfg_attr(not(feature = "io-copc"), allow(dead_code))]
113pub(crate) fn copc_parse(message: impl Into<String>) -> IoError {
114    IoError::CopcParse(message.into())
115}
116
117#[cfg_attr(not(feature = "io-copc"), allow(dead_code))]
118pub(crate) fn copc_format(message: impl Into<String>) -> IoError {
119    IoError::CopcFormat(message.into())
120}