From 645fe2ec01ddaf6e71b5b8074a8cf17c847dd157 Mon Sep 17 00:00:00 2001 From: Bruno Kirschner Date: Mon, 11 Oct 2021 15:58:49 +0200 Subject: [PATCH 1/2] Use default style if user-defined style is missing. Changes the serde configuration of the `RawConfig` struct to utilize a custom `Default` implementation to initialize new objects. This implementation contains the default style set as it was previously provided through the implementation of `RawConfig::new()`. This allows to utilize the default configuration until the user overwrites the related `RawStyleConfig` field, e.g. the description highlighting. .. fixes #149 --- src/config.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/config.rs b/src/config.rs index a4730fc6..cf41be39 100644 --- a/src/config.rs +++ b/src/config.rs @@ -178,21 +178,29 @@ impl Default for RawDirectoriesConfig { } } -#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)] +#[serde(default)] struct RawConfig { - #[serde(default)] style: RawStyleConfig, - #[serde(default)] display: RawDisplayConfig, - #[serde(default)] updates: RawUpdatesConfig, - #[serde(default)] directories: RawDirectoriesConfig, } impl RawConfig { fn new() -> Self { - let mut raw_config = Self::default(); + Self::default() + } +} + +impl Default for RawConfig { + fn default() -> Self { + let mut raw_config = RawConfig { + style: RawStyleConfig::default(), + display: RawDisplayConfig::default(), + updates: RawUpdatesConfig::default(), + directories: RawDirectoriesConfig::default() + }; // Set default config raw_config.style.example_text.foreground = Some(RawColor::Green); From 74a1a6586e47e74b21378b03d151792ae86298ee Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Sat, 16 Oct 2021 17:28:08 +0200 Subject: [PATCH 2/2] Run cargo fmt --- src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index cf41be39..758147aa 100644 --- a/src/config.rs +++ b/src/config.rs @@ -199,7 +199,7 @@ impl Default for RawConfig { style: RawStyleConfig::default(), display: RawDisplayConfig::default(), updates: RawUpdatesConfig::default(), - directories: RawDirectoriesConfig::default() + directories: RawDirectoriesConfig::default(), }; // Set default config