diff options
author | Eric Huss <eric@huss.org> | 2020-06-22 07:36:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-22 16:36:37 +0200 |
commit | 9a97f0a096dc6bac39683b6419945f20420d1720 (patch) | |
tree | f52838347ca90880d45776b1de779fabddaa0ba4 /src/config.rs | |
parent | bc23d08fa543b54a9fe9c71229a1a70ca9fcc104 (diff) |
Fix init creating empty `[rust]` table. (#1233)
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/src/config.rs b/src/config.rs index a4c5eb84..8496370c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -346,21 +346,17 @@ impl<'de> Deserialize<'de> for Config { impl Serialize for Config { fn serialize<S: Serializer>(&self, s: S) -> std::result::Result<S::Ok, S::Error> { - use serde::ser::Error; // TODO: This should probably be removed and use a derive instead. - let mut table = self.rest.clone(); - let book_config = match Value::try_from(self.book.clone()) { - Ok(cfg) => cfg, - Err(_) => { - return Err(S::Error::custom("Unable to serialize the BookConfig")); - } - }; - let rust_config = Value::try_from(&self.rust).expect("should always be serializable"); - + let book_config = Value::try_from(&self.book).expect("should always be serializable"); table.insert("book", book_config); - table.insert("rust", rust_config); + + if self.rust != RustConfig::default() { + let rust_config = Value::try_from(&self.rust).expect("should always be serializable"); + table.insert("rust", rust_config); + } + table.serialize(s) } } |