40 lines
970 B
Rust
40 lines
970 B
Rust
pub trait ModelArgs {
|
||
// 获取模型路径
|
||
fn model_path(&self) -> &str;
|
||
|
||
// 获取字符集(由于 Det 没有,所以返回 Option)
|
||
fn charset(&self) -> Option<&str>;
|
||
}
|
||
|
||
pub struct HasCharset {
|
||
pub charset: String,
|
||
} // 给 Ocr 和 Custom 用
|
||
pub struct NoCharset; // 给 Det 用
|
||
|
||
pub struct Model<T> {
|
||
pub path: String,
|
||
pub metadata: T,
|
||
}
|
||
// 针对有字符集的模型 (Ocr / Custom)
|
||
impl ModelArgs for Model<HasCharset> {
|
||
fn model_path(&self) -> &str {
|
||
&self.path
|
||
}
|
||
fn charset(&self) -> Option<&str> {
|
||
Some(&self.metadata.charset)
|
||
}
|
||
}
|
||
|
||
// 针对没有字符集的模型 (Det)
|
||
impl ModelArgs for Model<NoCharset> {
|
||
fn model_path(&self) -> &str {
|
||
&self.path
|
||
}
|
||
fn charset(&self) -> Option<&str> {
|
||
None
|
||
}
|
||
}
|
||
|
||
pub type OcrModel = Model<HasCharset>;
|
||
pub type DetModel = Model<NoCharset>;
|
||
pub type CustomModel = Model<HasCharset>; // Ocr 和 Custom 逻辑一致,可以复用
|