Store Addressbook in JSON

This commit is contained in:
Manos Pitsidianakis 2019-03-04 12:03:39 +02:00
parent b437e55b67
commit 5bffd8e966
No known key found for this signature in database
GPG Key ID: 73627C2F690DF710
3 changed files with 6 additions and 2 deletions

View File

@ -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"

View File

@ -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 {

View File

@ -40,6 +40,8 @@ extern crate termion;
#[macro_use]
extern crate nom;
extern crate serde_json;
use melib::*;
use std::collections::VecDeque;