opencv_core/
error.rs

1//! Error handling for OpenCV operations
2
3use thiserror::Error;
4
5/// OpenCV error types
6#[derive(Error, Debug)]
7pub enum Error {
8    #[error("Memory allocation failed: {0}")]
9    Memory(String),
10    
11    #[error("Invalid argument: {0}")]
12    InvalidArgument(String),
13    
14    #[error("Operation failed: {0}")]
15    Operation(String),
16    
17    #[error("I/O error: {0}")]
18    Io(String),
19    
20    #[error("CUDA error: {0}")]
21    Cuda(String),
22    
23    #[error("Type conversion error: {0}")]
24    TypeConversion(String),
25    
26    #[error("Index out of bounds: {0}")]
27    IndexOutOfBounds(String),
28    
29    #[error("Unsupported operation: {0}")]
30    Unsupported(String),
31    
32    #[error("External library error: {0}")]
33    External(String),
34}
35
36/// OpenCV result type
37pub type Result<T> = std::result::Result<T, Error>;
38
39impl From<std::io::Error> for Error {
40    fn from(err: std::io::Error) -> Self {
41        Error::Io(err.to_string())
42    }
43}
44
45impl From<anyhow::Error> for Error {
46    fn from(err: anyhow::Error) -> Self {
47        Error::External(err.to_string())
48    }
49}