refactor: minor change on source structure
This commit is contained in:
@@ -3,10 +3,12 @@ use rusqlite::Connection;
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Word(String, String);
|
||||
|
||||
pub struct FileDatabase {}
|
||||
pub struct FileDatabase<'a> {
|
||||
pub connection: &'a Connection,
|
||||
}
|
||||
|
||||
pub trait WordSource {
|
||||
fn find_by_word(&self, word: &str, connection: &Connection) -> Result<Vec<Word>, ()>;
|
||||
fn find_by_word(&self, word: &str) -> Result<Vec<Word>, ()>;
|
||||
fn insert_word(&mut self, word: Word) -> Result<(), ()>;
|
||||
fn remove_word(&self, word: &str) -> Result<(), ()>;
|
||||
fn edit_word(&mut self, word: Word) -> Result<(), ()>;
|
||||
@@ -20,9 +22,9 @@ fn fuzzy_compare(a: &str, b: &str) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
impl WordSource for FileDatabase {
|
||||
fn find_by_word(&self, word: &str, connection: &Connection) -> Result<Vec<Word>, ()> {
|
||||
let statement = connection.prepare("select key, description from word");
|
||||
impl<'a> WordSource for FileDatabase<'a> {
|
||||
fn find_by_word(&self, word: &str) -> Result<Vec<Word>, ()> {
|
||||
let statement = self.connection.prepare("select key, description from word");
|
||||
let mut word_list: Vec<Word> = vec![];
|
||||
|
||||
if let Ok(mut query) = statement {
|
||||
|
||||
Reference in New Issue
Block a user