diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-08-25 21:44:19 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-08-25 21:44:19 +0300 |
commit | 1328f994f31bcf88b40206e1aa840ece20da5f65 (patch) | |
tree | 991f440fc9a074291512fbcb40a2e9ae3b27b75b /ui/src/conf.rs | |
parent | 02b0f69e14e646f6bf5f7e423a1b46c45758e3eb (diff) |
Make config objects Serializable with serde
Diffstat (limited to 'ui/src/conf.rs')
-rw-r--r-- | ui/src/conf.rs | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/ui/src/conf.rs b/ui/src/conf.rs index 69022c10..f141559a 100644 --- a/ui/src/conf.rs +++ b/ui/src/conf.rs @@ -41,7 +41,8 @@ use melib::backends::SpecialUseMailbox; use melib::conf::AccountSettings; use melib::error::*; -use self::serde::{de, Deserialize, Deserializer}; +use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; + use std::collections::HashMap; use std::env; use std::fs::{File, OpenOptions}; @@ -88,7 +89,7 @@ impl ToggleFlag { } } -#[derive(Debug, Clone, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct FolderConf { rename: Option<String>, #[serde(default = "true_val")] @@ -119,7 +120,7 @@ impl FolderConf { } } -#[derive(Debug, Clone, Default, Deserialize)] +#[derive(Debug, Clone, Default, Serialize, Deserialize)] pub struct FileAccount { root_folder: String, format: String, @@ -247,7 +248,7 @@ impl FileAccount { } } -#[derive(Debug, Clone, Default, Deserialize)] +#[derive(Debug, Clone, Default, Serialize, Deserialize)] struct FileSettings { accounts: HashMap<String, FileAccount>, #[serde(default)] @@ -376,7 +377,7 @@ impl Settings { } } -#[derive(Copy, Debug, Clone, Deserialize)] +#[derive(Copy, Debug, Clone, Serialize, Deserialize)] pub enum IndexStyle { Plain, Threaded, @@ -426,6 +427,19 @@ where }) } +impl Serialize for ToggleFlag { + fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error> + where + S: Serializer, + { + match self { + ToggleFlag::Unset | ToggleFlag::InternalVal(_) => serializer.serialize_none(), + ToggleFlag::False => serializer.serialize_bool(false), + ToggleFlag::True => serializer.serialize_bool(true), + } + } +} + /* * Deserialize default functions */ |