diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-03-04 12:03:39 +0200 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-06-10 19:40:39 +0300 |
commit | 5bffd8e9666ab44f2aa9301c3eae9fc3cf128db4 (patch) | |
tree | 65cb26e2f79e04668da443f1306942e462b02a2c /ui | |
parent | b437e55b676585403d261f887514b5260591aee0 (diff) |
Store Addressbook in JSON
Diffstat (limited to 'ui')
-rw-r--r-- | ui/Cargo.toml | 1 | ||||
-rw-r--r-- | ui/src/conf/accounts.rs | 5 | ||||
-rw-r--r-- | ui/src/lib.rs | 2 |
3 files changed, 6 insertions, 2 deletions
diff --git a/ui/Cargo.toml b/ui/Cargo.toml index ff66bd2d..8050c82c 100644 --- a/ui/Cargo.toml +++ b/ui/Cargo.toml @@ -8,6 +8,7 @@ workspace = ".." xdg = "2.1.0" serde = "1.0.71" serde_derive = "1.0.71" +serde_json = "1.0" config = "0.6" chan = "0.1.21" chan-signal = "0.3.1" diff --git a/ui/src/conf/accounts.rs b/ui/src/conf/accounts.rs index 3024fdd5..43c2698a 100644 --- a/ui/src/conf/accounts.rs +++ b/ui/src/conf/accounts.rs @@ -67,6 +67,7 @@ pub struct Account { impl Drop for Account { fn drop(&mut self) { + //TODO: Avoid panics let data_dir = xdg::BaseDirectories::with_profile("meli", &self.name) .unwrap(); @@ -79,7 +80,7 @@ impl Drop for Account { } }; let writer = io::BufWriter::new(f); - bincode::serialize_into(writer, &self.address_book).unwrap(); + serde_json::to_writer(writer, &self.address_book).unwrap(); }; } } @@ -104,7 +105,7 @@ impl Account { let address_book = if let Ok(data) = data_dir.place_data_file("addressbook") { if data.exists() { let reader = io::BufReader::new(fs::File::open(data).unwrap()); - let result: result::Result<AddressBook, _> = bincode::deserialize_from(reader); + let result: result::Result<AddressBook, _> = serde_json::from_reader(reader); if let Ok(mut data_t) = result { data_t } else { diff --git a/ui/src/lib.rs b/ui/src/lib.rs index 7a8ba50a..f53eb565 100644 --- a/ui/src/lib.rs +++ b/ui/src/lib.rs @@ -40,6 +40,8 @@ extern crate termion; #[macro_use] extern crate nom; +extern crate serde_json; + use melib::*; use std::collections::VecDeque; |