1use std::fmt;
2
3pub type SpatialResult<T> = Result<T, SpatialError>;
4
5#[derive(Debug)]
6pub enum SpatialError {
7 ModelError(String),
8 ImageError(String),
9 TensorError(String),
10 IoError(String),
11 ConfigError(String),
12 Other(String),
13}
14
15impl fmt::Display for SpatialError {
16 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17 match self {
18 SpatialError::ModelError(msg) => write!(f, "Model error: {}", msg),
19 SpatialError::ImageError(msg) => write!(f, "Image error: {}", msg),
20 SpatialError::TensorError(msg) => write!(f, "Tensor error: {}", msg),
21 SpatialError::IoError(msg) => write!(f, "I/O error: {}", msg),
22 SpatialError::ConfigError(msg) => write!(f, "Configuration error: {}", msg),
23 SpatialError::Other(msg) => write!(f, "Error: {}", msg),
24 }
25 }
26}
27
28impl std::error::Error for SpatialError {}
29
30impl From<std::io::Error> for SpatialError {
31 fn from(e: std::io::Error) -> Self {
32 SpatialError::IoError(e.to_string())
33 }
34}
35
36impl From<image::ImageError> for SpatialError {
37 fn from(e: image::ImageError) -> Self {
38 SpatialError::ImageError(e.to_string())
39 }
40}