wordle_cli/
dictionary.rs

1use crate::db::db_dictionary::DbDictionary;
2
3use std::env;
4use dotenv::dotenv;
5
6/// Provides basic functions for reading and writing from and to a dictionary
7pub trait Dictionary {
8    fn get_random_word(&self) -> Option<DictionaryEntry>;
9    fn find_word(&self, text: &str) -> Option<DictionaryEntry>;
10    fn create_word(&self, word_entry: DictionaryEntry) -> Option<DictionaryEntry>;
11    fn guessed_word(&self, word_entry: DictionaryEntry);
12}
13
14/// Represents a dictionary entry
15pub struct DictionaryEntry {
16    pub word: String,
17    pub guessed: bool
18}
19
20pub fn get_dictionary(lang: &str) -> DbDictionary {
21    dotenv().ok();
22    DbDictionary::new(env::var("DATABASE_URL")
23                          .expect("DATABASE_URL must be set"), lang)
24}