WIP: word list interactions

This commit is contained in:
2026-06-13 00:37:51 +02:00
parent f02ee8fff9
commit 4c1ab25a9d
3 changed files with 55 additions and 6 deletions

View File

@@ -1,2 +1,2 @@
pub mod config;
pub mod database;
pub mod source;

View File

@@ -1,11 +1,60 @@
pub struct Database {
#[derive(Clone, Copy)]
pub struct Word(String, String);
pub struct FileDatabase {
path: String,
cached_words: Option<Vec<Word>>,
}
// TruthSource
pub trait WordSource {
fn find_word(&self, word: &str) -> Result<(), ()>;
fn insert_word(&self, word: &str) -> Result<(), ()>;
fn load(&self) -> Result<(), ()>;
fn find_word(&self, word: &str) -> Result<Word, ()>;
fn insert_word(&mut self, word: Word) -> Result<(), ()>;
fn remove_word(&self, word: &str) -> Result<(), ()>;
fn get_all_words(&self) -> Vec<String>;
fn edit_word(&mut self, word: Word) -> Result<(), ()>;
fn get_all_words(&self) -> Vec<Word>;
}
impl WordSource for FileDatabase {
fn load(&self) -> Result<(), ()> {}
fn find_word(&self, word: &str) -> Result<Word, ()> {
if let Some(words) = &self.cached_words {
if let Some(w) = words.into_iter().find(|&w| word == w.0) {
return Ok(w.clone());
}
}
// TODO: implement db alternative access
Err(())
}
fn insert_word(&mut self, word: Word) -> Result<(), ()> {
self.cached_words.get_or_insert(vec![]).push(word);
// TODO: insert into db
Ok(())
}
fn edit_word(&mut self, word: Word) -> Result<(), ()> {
if let Some(w) = self
.cached_words
.get_or_insert(vec![])
.iter()
.find(|&w| w.0 == word.0)
{
// ...
}
Ok(())
}
fn remove_word(&self, word: &str) -> Result<(), ()> {}
fn get_all_words(&self) -> Vec<Word> {
if let Some(words) = self.cached_words {
words
} else {
// Check db
()
}
}
}