Skip to content

Commit

Permalink
Don't serialize boolean fields if they're set to their default value
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeMathWalker committed Jan 16, 2025
1 parent 00b1d38 commit 01d1224
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ fn is_true(value: &bool) -> bool {
*value
}

fn is_false(value: &bool) -> bool {
!value
}

impl Manifest<Value> {
/// Parse contents of a `Cargo.toml` file already loaded as a byte slice.
///
Expand Down Expand Up @@ -656,12 +660,12 @@ pub struct Product {

/// If the product is meant to be a compiler plugin, this field must be set to true
/// for Cargo to correctly compile it and make it available for all dependencies.
#[serde(default)]
#[serde(default, skip_serializing_if = "is_false")]
pub plugin: bool,

/// If the product is meant to be a "macros 1.1" procedural macro, this field must
/// be set to true.
#[serde(default, alias = "proc_macro")]
#[serde(default, alias = "proc_macro", skip_serializing_if = "is_false")]
pub proc_macro: bool,

/// If set to false, `cargo test` will omit the `--test` flag to rustc, which
Expand Down

0 comments on commit 01d1224

Please sign in to comment.