forked from kageru/tracc
Add persistent storage via json
This commit is contained in:
parent
51cba3c68c
commit
d2c142f65f
|
@ -110,7 +110,11 @@ impl Tracc {
|
||||||
|
|
||||||
pub fn persist(self) {
|
pub fn persist(self) {
|
||||||
let string = serde_json::to_string(&self.todos).unwrap();
|
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()
|
.ok()
|
||||||
.or_else(|| panic!("Can’t save todos to JSON. Dumping raw data:\n{}", string))
|
.or_else(|| panic!("Can’t save todos to JSON. Dumping raw data:\n{}", string))
|
||||||
.map(|mut f| f.write(string.as_bytes()));
|
.map(|mut f| f.write(string.as_bytes()));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user