Don't serialize the default for book.src
This changes the serialization so that `book.src` is not serialized if it is the default. This removes the somewhat pointless `src = "src"` which shows up in the default `mdbook init` output. Deserialization should still default to `"src"`.
This commit is contained in:
parent
0043043bb3
commit
ae1a8c362c
3 changed files with 6 additions and 4 deletions
|
|
@ -297,6 +297,7 @@ pub struct BookConfig {
|
|||
/// An optional description for the book.
|
||||
pub description: Option<String>,
|
||||
/// Location of the book source relative to the book's root directory.
|
||||
#[serde(skip_serializing_if = "is_default_src")]
|
||||
pub src: PathBuf,
|
||||
/// The main language of the book.
|
||||
pub language: Option<String>,
|
||||
|
|
@ -305,6 +306,11 @@ pub struct BookConfig {
|
|||
pub text_direction: Option<TextDirection>,
|
||||
}
|
||||
|
||||
/// Helper for serde serialization.
|
||||
fn is_default_src(src: &PathBuf) -> bool {
|
||||
src == Path::new("src")
|
||||
}
|
||||
|
||||
impl Default for BookConfig {
|
||||
fn default() -> BookConfig {
|
||||
BookConfig {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ All done, no errors...
|
|||
str![[r#"
|
||||
[book]
|
||||
authors = []
|
||||
src = "src"
|
||||
language = "en"
|
||||
|
||||
"#]],
|
||||
|
|
@ -94,7 +93,6 @@ All done, no errors...
|
|||
str![[r#"
|
||||
[book]
|
||||
authors = []
|
||||
src = "src"
|
||||
language = "en"
|
||||
|
||||
"#]],
|
||||
|
|
@ -128,7 +126,6 @@ All done, no errors...
|
|||
[book]
|
||||
title = "Example title"
|
||||
authors = []
|
||||
src = "src"
|
||||
language = "en"
|
||||
|
||||
"#]],
|
||||
|
|
|
|||
|
|
@ -188,7 +188,6 @@ fn backends_receive_render_context_via_stdin() {
|
|||
"authors": [],
|
||||
"description": null,
|
||||
"language": "en",
|
||||
"src": "src",
|
||||
"text-direction": null,
|
||||
"title": null
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue