From d2c142f65f8f71549a45a83c9092a86f1576f105 Mon Sep 17 00:00:00 2001 From: kageru Date: Fri, 24 Jan 2020 08:11:07 +0100 Subject: [PATCH] Add persistent storage via json --- src/tracc.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/tracc.rs b/src/tracc.rs index 4db36c7..58b45d9 100644 --- a/src/tracc.rs +++ b/src/tracc.rs @@ -110,7 +110,11 @@ impl Tracc { pub fn persist(self) { let string = serde_json::to_string(&self.todos).unwrap(); - std::fs::OpenOptions::new().create(true).write(true).open(JSON_PATH) + std::fs::OpenOptions::new() + .create(true) + .write(true) + .truncate(true) + .open(JSON_PATH) .ok() .or_else(|| panic!("Can’t save todos to JSON. Dumping raw data:\n{}", string)) .map(|mut f| f.write(string.as_bytes()));