mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 19:22:26 +00:00
Switch db from json to toml
This commit is contained in:
@@ -49,15 +49,15 @@ pub trait CalendarStore: Send + Sync + 'static {
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct JsonCalendarStore {
|
||||
pub struct TomlCalendarStore {
|
||||
calendars: HashMap<String, Calendar>,
|
||||
events: HashMap<String, Event>,
|
||||
events: HashMap<String, HashMap<String, Event>>,
|
||||
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(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user