1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use std::path::PathBuf;

use jpreprocess_core::{word_entry::WordEntry, JPreprocessResult};

use crate::{Dictionary, DictionaryIter, DictionaryTrait};

pub struct JPreprocessDictionary(Dictionary);
impl DictionaryTrait for JPreprocessDictionary {
    type StoredType = WordEntry;

    fn load(dir: PathBuf) -> JPreprocessResult<Self> {
        let dict = Dictionary::load(
            dir.join("jpreprocess.words"),
            dir.join("jpreprocess.wordsidx"),
        )?;
        Ok(Self(dict))
    }
    fn get(&self, index: usize) -> Option<Self::StoredType> {
        self.0
            .get(index)
            .and_then(|data| bincode::deserialize(data).ok())
    }
    fn iter(&self) -> DictionaryIter<Self::StoredType> {
        DictionaryIter::new(self)
    }
}
impl From<Dictionary> for JPreprocessDictionary {
    fn from(dict: Dictionary) -> Self {
        Self(dict)
    }
}