10 changed files with 113 additions and 50 deletions
@ -0,0 +1,45 @@
|
||||
use std::collections::HashMap; |
||||
|
||||
#[derive(Debug, Default, Clone)] |
||||
pub struct DictEntry { |
||||
pub phoneme_in: String, |
||||
pub phoneme_out: String, |
||||
|
||||
pub not_before: Vec<String>, |
||||
pub not_after: Vec<String>, |
||||
|
||||
pub only_before: Vec<String>, |
||||
pub only_after: Vec<String>, |
||||
} |
||||
|
||||
impl DictEntry { |
||||
pub fn into_lowercase(self) -> Self { |
||||
DictEntry { |
||||
phoneme_in: self.phoneme_in.to_lowercase(), |
||||
phoneme_out: self.phoneme_out.to_lowercase(), |
||||
not_before: Self::lower_vec(self.not_before), |
||||
not_after: Self::lower_vec(self.not_after), |
||||
only_before: Self::lower_vec(self.only_before), |
||||
only_after: Self::lower_vec(self.only_after), |
||||
} |
||||
} |
||||
|
||||
fn lower_vec(vec: Vec<String>) -> Vec<String> { |
||||
vec.into_iter().map(|s| s.to_lowercase()).collect() |
||||
} |
||||
} |
||||
|
||||
pub type DictEntries = Vec<DictEntry>; |
||||
pub struct Dict { |
||||
name: String, |
||||
entries: DictEntries, |
||||
} |
||||
|
||||
pub type WordEntryId = u32; |
||||
|
||||
#[derive(Debug, Default)] |
||||
pub struct WordEntry { |
||||
id: Option<WordEntryId>, |
||||
word: String, |
||||
metadata: HashMap<String, String>, |
||||
} |
||||
@ -0,0 +1,15 @@
|
||||
use std::fmt; |
||||
|
||||
#[derive(Debug)] |
||||
pub enum RepositoryError { |
||||
NotFound, |
||||
ConnectionFailed, |
||||
InvalidData(String), |
||||
Unexpected(String), |
||||
} |
||||
|
||||
impl fmt::Display for RepositoryError { |
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
||||
write!(f, "{:?}", self) |
||||
} |
||||
} |
||||
@ -1,7 +1,11 @@
|
||||
pub mod entities; |
||||
pub mod errors; |
||||
pub mod major; |
||||
pub mod system; |
||||
pub mod traits; |
||||
|
||||
// pub use self::major::*;
|
||||
pub use self::entities::*; |
||||
pub use self::errors::*; |
||||
pub use self::system::*; |
||||
pub use self::traits::*; |
||||
|
||||
@ -1,3 +1,18 @@
|
||||
use crate::core::entities::{Dict, WordEntry, WordEntryId}; |
||||
use crate::core::errors::RepositoryError; |
||||
|
||||
pub trait SystemEncoder { |
||||
fn encode(&self, word: &str) -> String; |
||||
} |
||||
|
||||
pub trait WordRepository { |
||||
fn save(word: &WordEntry) -> Result<WordEntryId, RepositoryError>; |
||||
fn save_many(words: &Vec<WordEntry>) -> Result<(), RepositoryError>; |
||||
fn fetch(id: WordEntryId) -> Result<WordEntry, RepositoryError>; |
||||
fn fetch_many(ids: &Vec<WordEntryId>) -> Result<Vec<WordEntry>, RepositoryError>; |
||||
} |
||||
|
||||
pub trait DictRepository { |
||||
fn save(dict: &Dict) -> Result<(), RepositoryError>; |
||||
fn fetch(name: &str) -> Result<Dict, RepositoryError>; |
||||
} |
||||
|
||||
Loading…
Reference in new issue