feat: minor refactor to clarify configs with env + initial thoughs on truth source model

This commit is contained in:
2026-06-03 23:46:49 +02:00
parent cc22d3b719
commit f02ee8fff9
7 changed files with 53 additions and 20 deletions

View File

@@ -1,27 +1,14 @@
use std::fs::read_to_string;
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct Config {
pub database_path: String,
}
const DEFAULT_CONFIG_PATH: &'static str = "./src/assets/wordsmith_default.conf";
const DEFAULT_DATABASE_PATH: &'static str = "~/.config/wordsmith/wordsmith.db";
pub fn read_config(path: &str, default: Config) -> Config {
let mut config = default;
pub fn read_config(path: Option<&str>) -> Config {
let target_path: &str = {
if let Some(p) = path {
p
} else {
DEFAULT_CONFIG_PATH
}
};
let mut config = Config {
database_path: DEFAULT_DATABASE_PATH.to_string(),
};
for line in read_to_string(target_path).unwrap().lines() {
for line in read_to_string(path).unwrap().lines() {
if let Some((key, value)) = line.split_once(" ") {
match key {
"database_path" => {

View File

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

11
src/modules/source/mod.rs Normal file
View File

@@ -0,0 +1,11 @@
pub struct Database {
path: String,
}
// TruthSource
pub trait WordSource {
fn find_word(&self, word: &str) -> Result<(), ()>;
fn insert_word(&self, word: &str) -> Result<(), ()>;
fn remove_word(&self, word: &str) -> Result<(), ()>;
fn get_all_words(&self) -> Vec<String>;
}