use thiserror::Error;
pub type Result<T> = std::result::Result<T, OcrError>;
#[derive(Debug, Error)]
pub enum OcrError {
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Model error: {message}")]
Model {
message: String,
#[source]
source: Option<Box<dyn std::error::Error + Send + Sync>>,
},
#[error("Inference error: {message}")]
Inference {
message: String,
#[source]
source: Option<Box<dyn std::error::Error + Send + Sync>>,
},
#[error("Image error: {message}")]
Image {
message: String,
#[source]
source: Option<Box<dyn std::error::Error + Send + Sync>>,
},
#[error("Config error: {message}")]
Config {
message: String,
#[source]
source: Option<Box<dyn std::error::Error + Send + Sync>>,
},
#[error("{0}")]
Other(String),
}
impl OcrError {
pub fn model(message: impl Into<String>) -> Self {
Self::Model {
message: message.into(),
source: None,
}
}
pub fn inference(message: impl Into<String>) -> Self {
Self::Inference {
message: message.into(),
source: None,
}
}
pub fn image(message: impl Into<String>) -> Self {
Self::Image {
message: message.into(),
source: None,
}
}
pub fn config(message: impl Into<String>) -> Self {
Self::Config {
message: message.into(),
source: None,
}
}
}