diff --git a/crates/store/src/calendar.rs b/crates/store/src/calendar.rs index 47c2842..445cb16 100644 --- a/crates/store/src/calendar.rs +++ b/crates/store/src/calendar.rs @@ -49,15 +49,15 @@ pub trait CalendarStore: Send + Sync + 'static { } #[derive(Debug, Deserialize, Serialize)] -pub struct JsonCalendarStore { +pub struct TomlCalendarStore { calendars: HashMap, - events: HashMap, + events: HashMap>, path: String, } -impl JsonCalendarStore { +impl TomlCalendarStore { pub fn new(path: String) -> Self { - JsonCalendarStore { + TomlCalendarStore { calendars: HashMap::new(), events: HashMap::new(), path, @@ -66,8 +66,8 @@ impl JsonCalendarStore { pub async fn save(&self) -> Result<()> { let mut file = File::create(&self.path).await?; - let json = serde_json::to_string_pretty(&self)?; - file.write_all(json.as_bytes()).await?; + let output = toml::to_string_pretty(&self)?; + file.write_all(output.as_bytes()).await?; Ok(()) } } diff --git a/src/config.rs b/src/config.rs index 5b3623b..0618642 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,14 +1,14 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Deserialize, Serialize)] -pub struct JsonCalendarStoreConfig { +pub struct TomlCalendarStoreConfig { pub db_path: String, } #[derive(Debug, Deserialize, Serialize)] #[serde(tag = "backend", rename_all = "snake_case")] pub enum CalendarStoreConfig { - Json(JsonCalendarStoreConfig), + Toml(TomlCalendarStoreConfig), } #[derive(Debug, Deserialize, Serialize)] diff --git a/src/main.rs b/src/main.rs index 4419756..72bec96 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,11 +6,11 @@ use actix_web::middleware::{Logger, NormalizePath}; use actix_web::{web, App, HttpServer}; use anyhow::Result; use clap::Parser; -use config::{CalendarStoreConfig, JsonCalendarStoreConfig}; +use config::{CalendarStoreConfig, TomlCalendarStoreConfig}; use rustical_api::configure_api; use rustical_dav::{configure_dav, configure_well_known}; use rustical_frontend::configure_frontend; -use rustical_store::calendar::JsonCalendarStore; +use rustical_store::calendar::TomlCalendarStore; use tokio::sync::RwLock; mod config; @@ -30,10 +30,10 @@ async fn main() -> Result<()> { let config: Config = toml::from_str(&fs::read_to_string(&args.config_file)?)?; let cal_store = Arc::new(RwLock::new(match &config.calendar_store { - CalendarStoreConfig::Json(JsonCalendarStoreConfig { db_path }) => { + CalendarStoreConfig::Toml(TomlCalendarStoreConfig { db_path }) => { match fs::read_to_string(db_path) { - Ok(json) => serde_json::from_str::(&json).unwrap(), - Err(_) => JsonCalendarStore::new(db_path.to_string()), + Ok(content) => toml::from_str::(&content).unwrap(), + Err(_) => TomlCalendarStore::new(db_path.to_string()), } } }));