Skip to main content

oneocr_rs/
lib.rs

1mod bounding_box;
2mod errors;
3mod ffi;
4mod image_input;
5mod ocr_engine;
6mod ocr_line;
7mod ocr_options;
8mod ocr_result;
9mod ocr_word;
10
11// Re-export the public structs for easier access
12pub use bounding_box::BoundingBox;
13pub use bounding_box::Point;
14pub use errors::OneOcrError;
15pub use image_input::ImageInput;
16pub use ocr_engine::OcrEngine;
17pub use ocr_line::OcrLine;
18pub use ocr_options::{OcrOptions, Resolution};
19pub use ocr_result::OcrResult;
20pub use ocr_word::OcrWord;
21
22pub(crate) const ONE_OCR_MODEL_FILE_NAME: &str = "oneocr.onemodel";
23pub(crate) const ONE_OCR_MODEL_KEY: &str = r#"kj)TGtrK>f]b[Piow.gU+nC@s""""""4"#;
24
25/// A macro to check the result of an OCR call and return an error if it fails.
26/// This macro takes an expression `$call` and an error message `$err_msg`.
27/// If the result of `$call` is not 0, it returns an `OneOcrError::OcrApiError` error with the provided message.
28/// This macro is used to simplify error handling in the OCR engine methods.
29/// It helps to avoid repetitive error checking code and makes the code cleaner and more readable.
30macro_rules! check_ocr_call {
31    ($call:expr, $err_msg:literal) => {
32        let res = $call;
33        if res != 0 {
34            return Err($crate::errors::OneOcrError::OcrApiError {
35                // Use $crate for items from the macro's own crate
36                result: res,
37                message: $err_msg.to_string(),
38            });
39        }
40    };
41}
42
43pub(crate) use check_ocr_call;