-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoml_serialize.rs
More file actions
27 lines (22 loc) · 802 Bytes
/
toml_serialize.rs
File metadata and controls
27 lines (22 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use std::collections::HashMap;
use toml;
use crate::models::bookmark::Bookmark;
use crate::utils::error::*;
pub fn create_store_content(store : HashMap<String, String> ) -> String {
let mut store_map : HashMap<String, Vec<Bookmark>> = HashMap::new();
let mut bookmark_vec: Vec<Bookmark> = Vec::new();
for val in store {
let bm = Bookmark::new(val.0, val.1);
bookmark_vec.push(bm);
}
store_map.insert("bookmark".into(), bookmark_vec);
let toml = toml::to_string(&store_map);
match toml {
Ok(str) => { return str; }
Err(err) => {
print_error_and_exit(format!("Serialization error of store: {}", err.to_string()),
ErrorCode::StoreFileSerializationError);
}
}
return "".into();
}