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.
|
/// An optional description for the book.
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
/// Location of the book source relative to the book's root directory.
|
/// Location of the book source relative to the book's root directory.
|
||||||
|
#[serde(skip_serializing_if = "is_default_src")]
|
||||||
pub src: PathBuf,
|
pub src: PathBuf,
|
||||||
/// The main language of the book.
|
/// The main language of the book.
|
||||||
pub language: Option<String>,
|
pub language: Option<String>,
|
||||||
|
|
@ -305,6 +306,11 @@ pub struct BookConfig {
|
||||||
pub text_direction: Option<TextDirection>,
|
pub text_direction: Option<TextDirection>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Helper for serde serialization.
|
||||||
|
fn is_default_src(src: &PathBuf) -> bool {
|
||||||
|
src == Path::new("src")
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for BookConfig {
|
impl Default for BookConfig {
|
||||||
fn default() -> BookConfig {
|
fn default() -> BookConfig {
|
||||||
BookConfig {
|
BookConfig {
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ All done, no errors...
|
||||||
str![[r#"
|
str![[r#"
|
||||||
[book]
|
[book]
|
||||||
authors = []
|
authors = []
|
||||||
src = "src"
|
|
||||||
language = "en"
|
language = "en"
|
||||||
|
|
||||||
"#]],
|
"#]],
|
||||||
|
|
@ -94,7 +93,6 @@ All done, no errors...
|
||||||
str![[r#"
|
str![[r#"
|
||||||
[book]
|
[book]
|
||||||
authors = []
|
authors = []
|
||||||
src = "src"
|
|
||||||
language = "en"
|
language = "en"
|
||||||
|
|
||||||
"#]],
|
"#]],
|
||||||
|
|
@ -128,7 +126,6 @@ All done, no errors...
|
||||||
[book]
|
[book]
|
||||||
title = "Example title"
|
title = "Example title"
|
||||||
authors = []
|
authors = []
|
||||||
src = "src"
|
|
||||||
language = "en"
|
language = "en"
|
||||||
|
|
||||||
"#]],
|
"#]],
|
||||||
|
|
|
||||||
|
|
@ -188,7 +188,6 @@ fn backends_receive_render_context_via_stdin() {
|
||||||
"authors": [],
|
"authors": [],
|
||||||
"description": null,
|
"description": null,
|
||||||
"language": "en",
|
"language": "en",
|
||||||
"src": "src",
|
|
||||||
"text-direction": null,
|
"text-direction": null,
|
||||||
"title": null
|
"title": null
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue