Skip to main content

ocr_rs/
error.rs

1//! OCR error type definitions
2
3use thiserror::Error;
4
5use crate::mnn::MnnError;
6
7/// OCR error type
8#[derive(Error, Debug)]
9pub enum OcrError {
10    /// MNN inference engine error
11    #[error("MNN inference error: {0}")]
12    MnnError(#[from] MnnError),
13
14    /// Image processing error
15    #[error("Image processing error: {0}")]
16    ImageError(#[from] image::ImageError),
17
18    /// IO error
19    #[error("IO error: {0}")]
20    IoError(#[from] std::io::Error),
21
22    /// Invalid parameter error
23    #[error("Invalid parameter: {0}")]
24    InvalidParameter(String),
25
26    /// Model loading error
27    #[error("Model loading failed: {0}")]
28    ModelLoadError(String),
29
30    /// Preprocessing error
31    #[error("Preprocessing error: {0}")]
32    PreprocessError(String),
33
34    /// Postprocessing error
35    #[error("Postprocessing error: {0}")]
36    PostprocessError(String),
37
38    /// Detection error
39    #[error("Detection error: {0}")]
40    DetectionError(String),
41
42    /// Recognition error
43    #[error("Recognition error: {0}")]
44    RecognitionError(String),
45
46    /// Not initialized error
47    #[error("Not initialized: {0}")]
48    NotInitialized(String),
49
50    /// Charset parsing error
51    #[error("Charset parsing error: {0}")]
52    CharsetError(String),
53}
54
55/// OCR result type alias
56pub type OcrResult<T> = std::result::Result<T, OcrError>;