From f54a9f00b21348efb9d07db6e96ba7ac2aa2931b Mon Sep 17 00:00:00 2001 From: Lennart <18233294+lennart-k@users.noreply.github.com> Date: Tue, 5 Sep 2023 19:00:15 +0200 Subject: [PATCH] Cleaned update main.rs to the best of my limited knowledge --- src/main.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index eebbcf3..81246d7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,18 +28,15 @@ async fn main() -> Result<()> { let args = Args::parse(); let config: Config = toml::from_str(&fs::read_to_string(&args.config_file)?)?; - // TODO: Clean this jank up as soon more configuration options appear - let db_path = match config.calendar_store { - CalendarStoreConfig::Json(JsonCalendarStoreConfig { db_path }) => db_path, - }; - let cal_store = Arc::new(RwLock::new( - if let Ok(json) = fs::read_to_string(&db_path) { - serde_json::from_str::(&json)? - } else { - JsonCalendarStore::new(db_path.to_string()) - }, - )); + let cal_store = Arc::new(RwLock::new(match &config.calendar_store { + CalendarStoreConfig::Json(JsonCalendarStoreConfig { db_path }) => { + match fs::read_to_string(db_path) { + Ok(json) => serde_json::from_str::(&json).unwrap(), + Err(_) => JsonCalendarStore::new(db_path.to_string()), + } + } + })); HttpServer::new(move || { let cal_store = cal_store.clone();