use crate::{
cut::{LangChain, LangCut, LangPack, NoLang},
cutter::Cutter,
format::{Model, UserDict},
i18n::Lang,
};
#[derive(Clone, Copy, Debug)]
pub struct CutterBuilder<'a, E = NoLang> {
pub(crate) zh: Option<Model<'a>>,
pub(crate) ja: Option<Model<'a>>,
pub(crate) th: Option<Model<'a>>,
pub(crate) user_dict: Option<UserDict<'a>>,
pub(crate) ext: E,
}
impl Default for CutterBuilder<'_, NoLang> {
fn default() -> Self {
Self::new()
}
}
impl<'a> CutterBuilder<'a, NoLang> {
pub const fn new() -> Self {
Self {
zh: None,
ja: None,
th: None,
user_dict: None,
ext: NoLang,
}
}
pub fn with_lang_pack<P: LangPack>(self, ext: P) -> CutterBuilder<'a, P> {
CutterBuilder {
zh: self.zh,
ja: self.ja,
th: self.th,
user_dict: self.user_dict,
ext,
}
}
}
impl<'a, E> CutterBuilder<'a, E> {
pub const fn with_model(mut self, model: Model<'a>) -> Self {
match model.lang() {
Lang::Zh => self.zh = Some(model),
Lang::Ja => self.ja = Some(model),
Lang::Th => self.th = Some(model),
Lang::Ko | Lang::En | Lang::Ru | Lang::Ar => {}
}
self
}
pub const fn with_user_dict(mut self, user_dict: UserDict<'a>) -> Self {
self.user_dict = Some(user_dict);
self
}
pub fn with_lang<L: LangCut>(self, lang: L) -> CutterBuilder<'a, LangChain<L, E>> {
CutterBuilder {
zh: self.zh,
ja: self.ja,
th: self.th,
user_dict: self.user_dict,
ext: LangChain::new(lang, self.ext),
}
}
pub fn build(self) -> Cutter<'a, E> {
Cutter {
zh: self.zh,
ja: self.ja,
th: self.th,
user_dict: self.user_dict,
ext: self.ext,
}
}
}