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 { pub path: String, pub metadata: T, } // 针对有字符集的模型 (Ocr / Custom) impl ModelArgs for Model { fn model_path(&self) -> &str { &self.path } fn charset(&self) -> Option<&str> { Some(&self.metadata.charset) } } // 针对没有字符集的模型 (Det) impl ModelArgs for Model { fn model_path(&self) -> &str { &self.path } fn charset(&self) -> Option<&str> { None } } pub type OcrModel = Model; pub type DetModel = Model; pub type CustomModel = Model; // Ocr 和 Custom 逻辑一致,可以复用